mirror of
				https://github.com/1Panel-dev/1Panel.git
				synced 2025-10-31 19:26:02 +08:00 
			
		
		
		
	fix: 解决不带密码压缩文件失败的问题 (#5296)
Co-authored-by: ssonglius11 <ssonglius11@163.com>
This commit is contained in:
		
							parent
							
								
									33c4b8bba9
								
							
						
					
					
						commit
						428743d600
					
				
					 5 changed files with 38 additions and 10 deletions
				
			
		|  | @ -165,7 +165,11 @@ func handleTar(sourceDir, targetDir, name, exclusionRules string, secret string) | |||
| 	} else { | ||||
| 		commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s", targetDir+"/"+name, excludeRules, path) | ||||
| 	} | ||||
| 	global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) | ||||
| 	if len(secret) != 0 { | ||||
| 		global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) | ||||
| 	} else { | ||||
| 		global.LOG.Debug(commands) | ||||
| 	} | ||||
| 	stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour) | ||||
| 	if err != nil { | ||||
| 		if len(stdout) != 0 { | ||||
|  | @ -189,7 +193,11 @@ func handleUnTar(sourceFile, targetDir string, secret string) error { | |||
| 	} else { | ||||
| 		commands = fmt.Sprintf("tar -zxvf %s %s", sourceFile+" -C ", targetDir+" > /dev/null 2>&1") | ||||
| 	} | ||||
| 	global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) | ||||
| 	if len(secret) != 0 { | ||||
| 		global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) | ||||
| 	} else { | ||||
| 		global.LOG.Debug(commands) | ||||
| 	} | ||||
| 	stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour) | ||||
| 	if err != nil { | ||||
| 		global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err) | ||||
|  |  | |||
|  | @ -396,7 +396,11 @@ func (u *SnapshotService) handleUnTar(sourceDir, targetDir string, secret string | |||
| 	} else { | ||||
| 		commands = fmt.Sprintf("tar -zxvf %s %s", sourceDir+" -C ", targetDir+" > /dev/null 2>&1") | ||||
| 	} | ||||
| 	global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) | ||||
| 	if len(secret) != 0 { | ||||
| 		global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) | ||||
| 	} else { | ||||
| 		global.LOG.Debug(commands) | ||||
| 	} | ||||
| 	stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute) | ||||
| 	if err != nil { | ||||
| 		if len(stdout) != 0 { | ||||
|  |  | |||
|  | @ -261,7 +261,11 @@ func handleSnapTar(sourceDir, targetDir, name, exclusionRules string, secret str | |||
| 	} else { | ||||
| 		commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir) | ||||
| 	} | ||||
| 	global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) | ||||
| 	if len(secret) != 0 { | ||||
| 		global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) | ||||
| 	} else { | ||||
| 		global.LOG.Debug(commands) | ||||
| 	} | ||||
| 	stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute) | ||||
| 	if err != nil { | ||||
| 		if len(stdout) != 0 { | ||||
|  |  | |||
|  | @ -39,7 +39,7 @@ func (u *SnapshotService) HandleSnapshotRecover(snap model.Snapshot, isRecover b | |||
| 			req.IsNew = true | ||||
| 		} | ||||
| 		if req.IsNew || snap.InterruptStep == "Decompress" { | ||||
| 			if err := u.handleUnTar(fmt.Sprintf("%s/%s.tar.gz", baseDir, snap.Name), baseDir, req.Secret); err != nil { | ||||
| 			if err := handleUnTar(fmt.Sprintf("%s/%s.tar.gz", baseDir, snap.Name), baseDir, req.Secret); err != nil { | ||||
| 				updateRecoverStatus(snap.ID, isRecover, "Decompress", constant.StatusFailed, fmt.Sprintf("decompress file failed, err: %v", err)) | ||||
| 				return | ||||
| 			} | ||||
|  | @ -55,6 +55,9 @@ func (u *SnapshotService) HandleSnapshotRecover(snap model.Snapshot, isRecover b | |||
| 			req.IsNew = true | ||||
| 		} | ||||
| 		snapFileDir = fmt.Sprintf("%s/%s", baseDir, snap.Name) | ||||
| 		if _, err := os.Stat(snapFileDir); err != nil { | ||||
| 			snapFileDir = baseDir | ||||
| 		} | ||||
| 	} else { | ||||
| 		snapFileDir = fmt.Sprintf("%s/1panel_original/original_%s", global.CONF.System.BaseDir, snap.Name) | ||||
| 		if _, err := os.Stat(snapFileDir); err != nil { | ||||
|  |  | |||
|  | @ -2,10 +2,11 @@ package files | |||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"github.com/1Panel-dev/1Panel/backend/global" | ||||
| 	"github.com/1Panel-dev/1Panel/backend/utils/cmd" | ||||
| 	"path/filepath" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	"github.com/1Panel-dev/1Panel/backend/global" | ||||
| 	"github.com/1Panel-dev/1Panel/backend/utils/cmd" | ||||
| ) | ||||
| 
 | ||||
| type TarGzArchiver struct { | ||||
|  | @ -24,7 +25,11 @@ func (t TarGzArchiver) Extract(filePath, dstDir string, secret string) error { | |||
| 	} else { | ||||
| 		commands = fmt.Sprintf("tar -zxvf %s %s", filePath+" -C ", dstDir+" > /dev/null 2>&1") | ||||
| 	} | ||||
| 	global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) | ||||
| 	if len(secret) != 0 { | ||||
| 		global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) | ||||
| 	} else { | ||||
| 		global.LOG.Debug(commands) | ||||
| 	} | ||||
| 	if err = cmd.ExecCmd(commands); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | @ -48,9 +53,13 @@ func (t TarGzArchiver) Compress(sourcePaths []string, dstFile string, secret str | |||
| 		extraCmd := "| openssl enc -aes-256-cbc -salt -k " + secret + " -out" | ||||
| 		commands = fmt.Sprintf("tar -zcf %s %s %s", path, extraCmd, dstFile) | ||||
| 	} else { | ||||
| 		commands = fmt.Sprintf("tar -zcf %s %s", dstFile, path) | ||||
| 		commands = fmt.Sprintf("tar -zcf %s -C %s %s", dstFile, aheadDir, itemDir) | ||||
| 	} | ||||
| 	if len(secret) != 0 { | ||||
| 		global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) | ||||
| 	} else { | ||||
| 		global.LOG.Debug(commands) | ||||
| 	} | ||||
| 	global.LOG.Debug(strings.ReplaceAll(commands, secret, "******")) | ||||
| 	if err = cmd.ExecCmd(commands); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue