From d5caf847888b92bfeb60d5995d94b820ea75a2f7 Mon Sep 17 00:00:00 2001 From: Preston Thorpe <121899304+PThorpe92@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:11:34 -0500 Subject: [PATCH] Prompt on save/ existing file (#2714) * Update for fixing bug issue Adds YNprompt when user tries save new file as existing file name in current directory. https://github.com/zyedidia/micro/issues/2709 * Update actions.go error handled. gonna have to be tested on permission errors, etc --- internal/action/actions.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index dd92a364..fed54ed4 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -791,10 +791,27 @@ func (h *BufPane) SaveAsCB(action string, callback func()) bool { return } filename := strings.Join(args, " ") - noPrompt := h.saveBufToFile(filename, action, callback) - if noPrompt { - h.completeAction(action) + fileinfo, err := os.Stat(filename) + if err != nil { + if os.IsNotExist(err) { + noPrompt := h.saveBufToFile(filename, action, callback) + if noPrompt { + h.completeAction(action) + return + } + } } + InfoBar.YNPrompt( + fmt.Sprintf("the file %s already exists in the directory, would you like to overwrite? Y/n", fileinfo.Name()), + func(yes, canceled bool) { + if yes && !canceled { + noPrompt := h.saveBufToFile(filename, action, callback) + if noPrompt { + h.completeAction(action) + } + } + }, + ) } }) return false