| 1267 | } |
| 1268 | |
| 1269 | func (f FileOp) DecompressGzFile(ctx context.Context, srcFile, dst string) error { |
| 1270 | var archiveModTime time.Time |
| 1271 | if st, err := f.Fs.Stat(srcFile); err == nil { |
| 1272 | archiveModTime = st.ModTime() |
| 1273 | } |
| 1274 | |
| 1275 | in, err := f.Fs.Open(srcFile) |
| 1276 | if err != nil { |
| 1277 | return fmt.Errorf("open source file failed: %w", err) |
| 1278 | } |
| 1279 | defer in.Close() |
| 1280 | |
| 1281 | gr, err := gzip.NewReader(&contextReader{ctx: ctx, r: in}) |
| 1282 | if err != nil { |
| 1283 | return fmt.Errorf("gzip reader creation failed: %w", err) |
| 1284 | } |
| 1285 | defer gr.Close() |
| 1286 | |
| 1287 | outName := "" |
| 1288 | if gr.Name != "" { |
| 1289 | outName = filepath.Base(gr.Name) |
| 1290 | } |
| 1291 | if outName == "" || outName == "." { |
| 1292 | outName = strings.TrimSuffix(filepath.Base(srcFile), ".gz") |
| 1293 | } |
| 1294 | outPath := filepath.Join(dst, outName) |
| 1295 | parentDir := filepath.Dir(outPath) |
| 1296 | if !f.Stat(parentDir) { |
| 1297 | if err := f.Fs.MkdirAll(parentDir, 0755); err != nil { |
| 1298 | return err |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | fw, err := f.Fs.OpenFile(outPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644) |
| 1303 | if err != nil { |
| 1304 | return fmt.Errorf("create output file failed: %w", err) |
| 1305 | } |
| 1306 | defer fw.Close() |
| 1307 | |
| 1308 | if _, err := io.Copy(fw, gr); err != nil { |
| 1309 | return fmt.Errorf("copy content failed: %w", err) |
| 1310 | } |
| 1311 | |
| 1312 | if !archiveModTime.IsZero() { |
| 1313 | _ = os.Chtimes(outPath, archiveModTime, archiveModTime) |
| 1314 | } |
| 1315 | |
| 1316 | return nil |
| 1317 | } |
| 1318 | |
| 1319 | func (f FileOp) TarGzCompressPro(withDir bool, src, dst, secret, exclusionRules string) error { |
| 1320 | if !f.Stat(path.Dir(dst)) { |