final auto unzip code tweaks

This commit is contained in:
Evan Su 2025-01-27 00:55:47 -05:00
parent bf73698c52
commit a929eb1037

View file

@ -2387,17 +2387,25 @@ func unpackArchive(zipPath string) error {
var done int64 var done int64
startTime := time.Now() startTime := time.Now()
for i, f := range reader.File { for _, f := range reader.File {
outPath := filepath.Join(extractDir, f.Name) outPath := filepath.Join(extractDir, filepath.Clean(strings.ReplaceAll(f.Name, "\\", "/")))
// Make directory if current entry is a folder // Make directory if current entry is a folder
if f.FileInfo().IsDir() { if f.FileInfo().IsDir() {
if err := os.MkdirAll(outPath, f.Mode()); err != nil { if err := os.MkdirAll(outPath, f.Mode()); err != nil {
return err return err
} }
}
}
for i, f := range reader.File {
// Already handled above
if f.FileInfo().IsDir() {
continue continue
} }
outPath := filepath.Join(extractDir, filepath.Clean(strings.ReplaceAll(f.Name, "\\", "/")))
// Otherwise create necessary parent directories // Otherwise create necessary parent directories
if err := os.MkdirAll(filepath.Dir(outPath), 0755); err != nil { if err := os.MkdirAll(filepath.Dir(outPath), 0755); err != nil {
return err return err
@ -2426,7 +2434,6 @@ func unpackArchive(zipPath string) error {
return writeErr return writeErr
} }
// Update "done" and recalc progress, speed, eta
done += int64(n) done += int64(n)
progress, speed, eta = statify(done, totalSize, startTime) progress, speed, eta = statify(done, totalSize, startTime)
progressInfo = fmt.Sprintf("%d/%d", i+1, len(reader.File)) progressInfo = fmt.Sprintf("%d/%d", i+1, len(reader.File))