From b3668a6f5c16f5191aa4a75e00dc82954b112133 Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 20 May 2024 08:31:47 -0700 Subject: [PATCH] fix: prompt for overwriting when unzipping --- src/utils/utils.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/utils/utils.go b/src/utils/utils.go index 75a1f122..d395d108 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -447,6 +447,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)