d
This commit is contained in:
@@ -608,7 +608,55 @@ func JudgeRpmOrDebPackage(filePath string) (int, error) {
|
||||
} else if string(header) == "!<arch\n" || string(header) == "!<arch\r" {
|
||||
fileType = 2
|
||||
} else {
|
||||
fileType = 3
|
||||
fileType = 0
|
||||
}
|
||||
|
||||
return fileType, nil
|
||||
}
|
||||
|
||||
func isRpmPackage(file *os.File) bool {
|
||||
// RPM packages start with the magic number "EDABEEDB"
|
||||
magic := []byte{0xED, 0xAB, 0xEE, 0xDB}
|
||||
buffer := make([]byte, len(magic))
|
||||
|
||||
_, err := file.Read(buffer)
|
||||
if err != nil && err != io.EOF {
|
||||
return false
|
||||
}
|
||||
|
||||
return string(buffer) == string(magic)
|
||||
}
|
||||
|
||||
func isDebPackage(file *os.File) bool {
|
||||
// DEB packages start with the magic number "!<arch>\n"
|
||||
magic := []byte("!<arch>\n")
|
||||
buffer := make([]byte, len(magic))
|
||||
|
||||
_, err := file.Read(buffer)
|
||||
if err != nil && err != io.EOF {
|
||||
return false
|
||||
}
|
||||
|
||||
return string(buffer) == string(magic)
|
||||
}
|
||||
|
||||
func IsRpmOrDebPackage(filePath string) (int, error) {
|
||||
var fileType int = 0
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return fileType, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
isRpm := isRpmPackage(file)
|
||||
isDeb := isDebPackage(file)
|
||||
|
||||
if isRpm {
|
||||
fileType = 1
|
||||
} else if isDeb {
|
||||
fileType = 2
|
||||
} else {
|
||||
fileType = 0
|
||||
}
|
||||
|
||||
return fileType, nil
|
||||
|
||||
Reference in New Issue
Block a user