Skip to content

Commit

Permalink
Merge pull request #698 from schollz/schollz/issue594
Browse files Browse the repository at this point in the history
fix: prompt for overwriting when unzipping
  • Loading branch information
schollz authored May 20, 2024
2 parents 3f12f75 + b3668a6 commit 4929635
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,16 @@ func UnzipDirectory(destination string, source string) error {
log.Fatalln(err)
}

// check if file exists
if _, err := os.Stat(filePath); err == nil {
prompt := fmt.Sprintf("\nOverwrite '%s'? (y/N) ", filePath)
choice := strings.ToLower(GetInput(prompt))
if choice != "y" && choice != "yes" {
fmt.Fprintf(os.Stderr, "skipping '%s'", filePath)
continue
}
}

dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
log.Fatalln(err)
Expand Down

0 comments on commit 4929635

Please sign in to comment.