mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix(image): optimized iso format check
This commit is contained in:
@@ -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"))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user