From a4ca078edff55deea45e780fa9a2dfb4e36030ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sat, 9 Dec 2023 20:51:27 +0100 Subject: [PATCH] actions: saveas: Fix crash at access without permission --- internal/action/actions.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 74e701f47..d45f5b2f0 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -793,25 +793,26 @@ func (h *BufPane) SaveAsCB(action string, callback func()) bool { filename := strings.Join(args, " ") fileinfo, err := os.Stat(filename) if err != nil { - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) || errors.Is(err, fs.ErrPermission) { 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) + } else { + 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