fix(image): optimized iso format check

This commit is contained in:
ioito
2023-06-29 14:05:04 +08:00
parent 1a0137ff90
commit 70af8c46c7
2 changed files with 19 additions and 6 deletions
+16
View File
@@ -16,6 +16,7 @@ package fileutils2
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
@@ -373,3 +374,18 @@ func GetDevUuid(dev string) (map[string]string, error) {
}
return map[string]string{}, nil
}
func IsIsoFile(sPath string) bool {
file, err := os.Open(sPath)
if err != nil {
return false
}
defer file.Close()
file.Seek(0x8001, 0)
buffer := make([]byte, 5)
_, err = file.Read(buffer)
if err != nil {
return false
}
return bytes.Equal(buffer, []byte("CD001"))
}
+3 -6
View File
@@ -211,12 +211,9 @@ func (img *SQemuImage) parse() error {
img.EncryptAlg = seclib2.TSymEncAlg(info.FormatSpecific.Data.Encrypt.CipherAlg)
}
if img.Format == qemuimgfmt.RAW && fileutils2.IsFile(img.Path) {
// test if it is an ISO
blkType := fileutils2.GetBlkidType(img.Path)
if utils.IsInStringArray(blkType, []string{"iso9660", "udf"}) {
img.Format = qemuimgfmt.ISO
}
// test if it is an ISO
if img.Format == qemuimgfmt.RAW && fileutils2.IsFile(img.Path) && fileutils2.IsIsoFile(img.Path) {
img.Format = qemuimgfmt.ISO
}
return nil
}