mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
fix: 解决主机文件压缩解压特殊字符问题 (#6451)
This commit is contained in:
parent
08c0faa20e
commit
0122b4c6ce
@ -613,6 +613,9 @@ func (f FileOp) decompressWithSDK(srcFile string, dst string, cType CompressType
|
|||||||
func (f FileOp) Decompress(srcFile string, dst string, cType CompressType, secret string) error {
|
func (f FileOp) Decompress(srcFile string, dst string, cType CompressType, secret string) error {
|
||||||
if cType == Tar || cType == Zip || cType == TarGz {
|
if cType == Tar || cType == Zip || cType == TarGz {
|
||||||
shellArchiver, err := NewShellArchiver(cType)
|
shellArchiver, err := NewShellArchiver(cType)
|
||||||
|
if !f.Stat(dst) {
|
||||||
|
_ = f.CreateDir(dst, 0755)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err = shellArchiver.Extract(srcFile, dst, secret); err == nil {
|
if err = shellArchiver.Extract(srcFile, dst, secret); err == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -18,7 +18,7 @@ func NewTarArchiver(compressType CompressType) ShellArchiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t TarArchiver) Extract(FilePath string, dstDir string, secret string) error {
|
func (t TarArchiver) Extract(FilePath string, dstDir string, secret string) error {
|
||||||
return cmd.ExecCmd(fmt.Sprintf("%s %s %s -C %s", t.Cmd, t.getOptionStr("extract"), FilePath, dstDir))
|
return cmd.ExecCmd(fmt.Sprintf("%s %s \"%s\" -C \"%s\"", t.Cmd, t.getOptionStr("extract"), FilePath, dstDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TarArchiver) Compress(sourcePaths []string, dstFile string, secret string) error {
|
func (t TarArchiver) Compress(sourcePaths []string, dstFile string, secret string) error {
|
||||||
|
@ -20,11 +20,11 @@ func (t TarGzArchiver) Extract(filePath, dstDir string, secret string) error {
|
|||||||
var err error
|
var err error
|
||||||
commands := ""
|
commands := ""
|
||||||
if len(secret) != 0 {
|
if len(secret) != 0 {
|
||||||
extraCmd := "openssl enc -d -aes-256-cbc -k '" + secret + "' -in " + filePath + " | "
|
extraCmd := fmt.Sprintf("openssl enc -d -aes-256-cbc -k '%s' -in '%s' | ", secret, filePath)
|
||||||
commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, dstDir+" > /dev/null 2>&1")
|
commands = fmt.Sprintf("%s tar -zxvf - -C '%s' > /dev/null 2>&1", extraCmd, dstDir)
|
||||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||||
} else {
|
} else {
|
||||||
commands = fmt.Sprintf("tar -zxvf %s %s", filePath+" -C ", dstDir+" > /dev/null 2>&1")
|
commands = fmt.Sprintf("tar -zxvf '%s' -C '%s' > /dev/null 2>&1", filePath, dstDir)
|
||||||
global.LOG.Debug(commands)
|
global.LOG.Debug(commands)
|
||||||
}
|
}
|
||||||
if err = cmd.ExecCmd(commands); err != nil {
|
if err = cmd.ExecCmd(commands); err != nil {
|
||||||
@ -34,27 +34,25 @@ func (t TarGzArchiver) Extract(filePath, dstDir string, secret string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t TarGzArchiver) Compress(sourcePaths []string, dstFile string, secret string) error {
|
func (t TarGzArchiver) Compress(sourcePaths []string, dstFile string, secret string) error {
|
||||||
var err error
|
var itemDirs []string
|
||||||
path := ""
|
|
||||||
itemDir := ""
|
|
||||||
for _, item := range sourcePaths {
|
for _, item := range sourcePaths {
|
||||||
itemDir += filepath.Base(item) + " "
|
itemDirs = append(itemDirs, fmt.Sprintf("\"%s\"", filepath.Base(item)))
|
||||||
}
|
}
|
||||||
aheadDir := dstFile[:strings.LastIndex(dstFile, "/")]
|
itemDir := strings.Join(itemDirs, " ")
|
||||||
|
aheadDir := filepath.Dir(sourcePaths[0])
|
||||||
if len(aheadDir) == 0 {
|
if len(aheadDir) == 0 {
|
||||||
aheadDir = "/"
|
aheadDir = "/"
|
||||||
}
|
}
|
||||||
path += fmt.Sprintf("- -C %s %s", aheadDir, itemDir)
|
|
||||||
commands := ""
|
commands := ""
|
||||||
if len(secret) != 0 {
|
if len(secret) != 0 {
|
||||||
extraCmd := "| openssl enc -aes-256-cbc -salt -k '" + secret + "' -out"
|
extraCmd := fmt.Sprintf("| openssl enc -aes-256-cbc -salt -k '%s' -out '%s'", secret, dstFile)
|
||||||
commands = fmt.Sprintf("tar -zcf %s %s %s", path, extraCmd, dstFile)
|
commands = fmt.Sprintf("tar -zcf - -C \"%s\" %s %s", aheadDir, itemDir, extraCmd)
|
||||||
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******"))
|
||||||
} else {
|
} else {
|
||||||
commands = fmt.Sprintf("tar -zcf %s -C %s %s", dstFile, aheadDir, itemDir)
|
commands = fmt.Sprintf("tar -zcf \"%s\" -C \"%s\" %s", dstFile, aheadDir, itemDir)
|
||||||
global.LOG.Debug(commands)
|
global.LOG.Debug(commands)
|
||||||
}
|
}
|
||||||
if err = cmd.ExecCmd(commands); err != nil {
|
if err := cmd.ExecCmd(commands); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user