Skip to content

Commit

Permalink
Fix gopass update writable check
Browse files Browse the repository at this point in the history
Fixes gopasspw#1837

RELEASE_NOTES=[BUGFIX] Fix gopass update

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz committed Mar 13, 2021
1 parent fb02b5c commit cb9642a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions internal/action/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
9 changes: 9 additions & 0 deletions internal/updater/access_others.go
Original file line number Diff line number Diff line change
@@ -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)
}
7 changes: 7 additions & 0 deletions internal/updater/access_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build windows

package updater

func canWrite(path string) error {
return nil
}
12 changes: 0 additions & 12 deletions internal/updater/updateable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cb9642a

Please sign in to comment.