MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Decompress

Method Decompress

agent/utils/files/file_op.go:1103–1128  ·  view source on GitHub ↗
(ctx context.Context, srcFile string, dst string, cType CompressType, secret string)

Source from the content-addressed store, hash-verified

1101}
1102
1103func (f FileOp) Decompress(ctx context.Context, srcFile string, dst string, cType CompressType, secret string) error {
1104 if cType == Tar || cType == Zip || cType == TarGz || cType == Rar || cType == X7z {
1105 shellArchiver, err := NewExtractShellArchiver(cType)
1106 if !f.Stat(dst) {
1107 _ = f.CreateDir(dst, 0755)
1108 }
1109 if err == nil {
1110 if err = shellArchiver.Extract(ctx, srcFile, dst, secret); err == nil {
1111 return nil
1112 }
1113 if cType == TarGz {
1114 if strings.Contains(err.Error(), "bad decrypt") {
1115 return buserr.New("ErrBadDecrypt")
1116 }
1117 if err := shellArchiver.Extract(ctx, srcFile, dst, "-"); strings.Contains(err.Error(), "bad decrypt") {
1118 return buserr.New("ErrBadDecrypt")
1119 }
1120 }
1121 } else {
1122 if cType == Rar || cType == X7z {
1123 return err
1124 }
1125 }
1126 }
1127 return f.decompressWithSDK(ctx, srcFile, dst, cType)
1128}
1129
1130func ZipFile(ctx context.Context, files []archiver.File, dst afero.File, progress func(current, total int, message string)) error {
1131 zw := zip.NewWriter(dst)

Callers 3

DeCompressMethod · 0.95
downloadAppFunction · 0.95
getAppFromRepoFunction · 0.95

Calls 6

StatMethod · 0.95
CreateDirMethod · 0.95
decompressWithSDKMethod · 0.95
NewExtractShellArchiverFunction · 0.85
ExtractMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected