1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-27 12:34:19 +03:00

Merge pull request #698 from schollz/schollz/issue594

fix: prompt for overwriting when unzipping
This commit is contained in:
Zack 2024-05-20 09:53:09 -07:00 committed by GitHub
commit 4929635eb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)