mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
feat(glance): upload tar as TGZ image (#21952)
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
@@ -474,10 +475,23 @@ func IsTarGzipFile(fPath string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
tarReader := tar.NewReader(gzf)
|
||||
_, err = tarReader.Next()
|
||||
return IsTarStream(gzf)
|
||||
}
|
||||
|
||||
func IsTarStream(f io.Reader) bool {
|
||||
tarReader := tar.NewReader(f)
|
||||
_, err := tarReader.Next()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsTarFile(fPath string) bool {
|
||||
f, err := os.Open(fPath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer f.Close()
|
||||
return IsTarStream(f)
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ func (img *SQemuImage) parse() error {
|
||||
if img.Format == qemuimgfmt.RAW && fileutils2.IsFile(img.Path) && fileutils2.IsIsoFile(img.Path) {
|
||||
img.Format = qemuimgfmt.ISO
|
||||
}
|
||||
if img.Format == qemuimgfmt.RAW && fileutils2.IsFile(img.Path) && fileutils2.IsTarGzipFile(img.Path) {
|
||||
if img.Format == qemuimgfmt.RAW && fileutils2.IsFile(img.Path) && (fileutils2.IsTarGzipFile(img.Path) || fileutils2.IsTarFile(img.Path)) {
|
||||
img.Format = imageapi.IMAGE_DISK_FORMAT_TGZ
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user