diff --git a/internal/action/errors.go b/internal/action/errors.go index 14951d306a..61fb268f66 100644 --- a/internal/action/errors.go +++ b/internal/action/errors.go @@ -54,8 +54,9 @@ const ( // ExitError returns a user friendly CLI error func ExitError(exitCode int, err error, format string, args ...interface{}) error { + msg := fmt.Sprintf(format, args...) if err != nil { - debug.Log("Stacktrace: %+v", err) + debug.Log("%s - stacktrace: %+v", err) } - return cli.Exit(fmt.Sprintf(format, args...), exitCode) + return cli.Exit(msg, exitCode) } diff --git a/internal/updater/access_others.go b/internal/updater/access_others.go new file mode 100644 index 0000000000..079af20a1a --- /dev/null +++ b/internal/updater/access_others.go @@ -0,0 +1,9 @@ +// +build !windows + +package updater + +import "golang.org/x/sys/unix" + +func canWrite(path string) error { + return unix.Access(path, unix.W_OK) +} diff --git a/internal/updater/access_windows.go b/internal/updater/access_windows.go new file mode 100644 index 0000000000..fdd7b682b7 --- /dev/null +++ b/internal/updater/access_windows.go @@ -0,0 +1,7 @@ +// +build windows + +package updater + +func canWrite(path string) error { + return nil +} diff --git a/internal/updater/updateable.go b/internal/updater/updateable.go index d732eee199..80de30bf1d 100644 --- a/internal/updater/updateable.go +++ b/internal/updater/updateable.go @@ -50,18 +50,6 @@ func IsUpdateable(ctx context.Context) error { return nil } -func canWrite(path string) error { - // check if we can write to this file. we open it for writing in - // append mode to not truncate it and immediately close the filehandle since - // we're only interested in the error. - fh, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0755) - if e := fh.Close(); err != nil { - return e - } - - return err -} - var executable = func(ctx context.Context) (string, error) { path, err := os.Executable() if err != nil {