commit 44275e61d3532984ceead0ab22c305d25722eb87
parent bbbd724942284972defdb7efb2e1749570b49614
Author: Sean Enck <sean@ttypty.com>
Date: Sat, 1 Apr 2023 11:54:43 -0400
use upstream for this
Diffstat:
2 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/internal/backend/core.go b/internal/backend/core.go
@@ -7,6 +7,7 @@ import (
"strings"
"github.com/enckse/lockbox/internal/inputs"
+ "github.com/enckse/pgl/os/paths"
"github.com/tobischo/gokeepasslib/v3"
)
@@ -22,7 +23,7 @@ func loadFile(file string, must bool) (*Transaction, error) {
if !strings.HasSuffix(file, ".kdbx") {
return nil, errors.New("should use a .kdbx extension")
}
- exists := pathExists(file)
+ exists := paths.Exist(file)
if must {
if !exists {
return nil, errors.New("invalid file, does not exist")
@@ -42,7 +43,7 @@ func NewTransaction() (*Transaction, error) {
func getCredentials(key, keyFile string) (*gokeepasslib.DBCredentials, error) {
if len(keyFile) > 0 {
- if !pathExists(keyFile) {
+ if !paths.Exist(keyFile) {
return nil, errors.New("no keyfile found on disk")
}
return gokeepasslib.NewPasswordAndKeyCredentials(key, keyFile)
@@ -78,14 +79,6 @@ func encode(f *os.File, db *gokeepasslib.Database) error {
return gokeepasslib.NewEncoder(f).Encode(db)
}
-// pathExists indicates if a path exists.
-func pathExists(path string) bool {
- if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
- return false
- }
- return true
-}
-
func isTOTP(title string) (bool, error) {
t := inputs.TOTPToken()
if t == notesKey || t == passKey || t == titleKey {
diff --git a/internal/backend/hooks.go b/internal/backend/hooks.go
@@ -10,6 +10,7 @@ import (
"github.com/enckse/lockbox/internal/inputs"
"github.com/enckse/pgl/os/env"
+ "github.com/enckse/pgl/os/paths"
)
// NewHook will create a new hook type
@@ -21,7 +22,7 @@ func NewHook(path string, a ActionMode) (Hook, error) {
if dir == "" {
return Hook{enabled: false}, nil
}
- if !pathExists(dir) {
+ if !paths.Exist(dir) {
return Hook{}, errors.New("hook directory does NOT exist")
}
entries, err := os.ReadDir(dir)