commit d24f7fadd4ec1c907cbf8ceb741d9c82338f6506
parent c4975578c27f6d00e4147edf81e0cceafeab8c91
Author: Sean Enck <sean@ttypty.com>
Date: Tue, 25 Jul 2023 19:58:33 -0400
move paths to platform
Diffstat:
6 files changed, 41 insertions(+), 40 deletions(-)
diff --git a/internal/backend/core.go b/internal/backend/core.go
@@ -7,7 +7,7 @@ import (
"strings"
"github.com/enckse/lockbox/internal/inputs"
- "github.com/enckse/lockbox/internal/system"
+ "github.com/enckse/lockbox/internal/platform"
"github.com/tobischo/gokeepasslib/v3"
)
@@ -23,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 := system.PathExists(file)
+ exists := platform.PathExists(file)
if must {
if !exists {
return nil, errors.New("invalid file, does not exist")
@@ -61,7 +61,7 @@ func splitComponents(path string) ([]string, string, error) {
func getCredentials(key, keyFile string) (*gokeepasslib.DBCredentials, error) {
if len(keyFile) > 0 {
- if !system.PathExists(keyFile) {
+ if !platform.PathExists(keyFile) {
return nil, errors.New("no keyfile found on disk")
}
return gokeepasslib.NewPasswordAndKeyCredentials(key, keyFile)
diff --git a/internal/backend/hooks.go b/internal/backend/hooks.go
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/enckse/lockbox/internal/inputs"
+ "github.com/enckse/lockbox/internal/platform"
"github.com/enckse/lockbox/internal/system"
)
@@ -21,7 +22,7 @@ func NewHook(path string, a ActionMode) (Hook, error) {
if dir == "" {
return Hook{enabled: false}, nil
}
- if !system.PathExists(dir) {
+ if !platform.PathExists(dir) {
return Hook{}, errors.New("hook directory does NOT exist")
}
entries, err := os.ReadDir(dir)
diff --git a/internal/platform/paths.go b/internal/platform/paths.go
@@ -0,0 +1,15 @@
+// Package platform is responsible for pathing operations/commands
+package platform
+
+import (
+ "errors"
+ "os"
+)
+
+// PathExists indicates whether a path exists (true) or not (false)
+func PathExists(file string) bool {
+ if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) {
+ return false
+ }
+ return true
+}
diff --git a/internal/platform/paths_test.go b/internal/platform/paths_test.go
@@ -0,0 +1,21 @@
+package platform_test
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/enckse/lockbox/internal/platform"
+)
+
+func TestPathExist(t *testing.T) {
+ testDir := filepath.Join("testdata", "exists")
+ os.RemoveAll(testDir)
+ if platform.PathExists(testDir) {
+ t.Error("test dir SHOULD NOT exist")
+ }
+ os.MkdirAll(testDir, 0o755)
+ if !platform.PathExists(testDir) {
+ t.Error("test dir SHOULD exist")
+ }
+}
diff --git a/internal/system/paths.go b/internal/system/paths.go
@@ -1,15 +0,0 @@
-// Package system is responsible for pathing operations/commands
-package system
-
-import (
- "errors"
- "os"
-)
-
-// PathExists indicates whether a path exists (true) or not (false)
-func PathExists(file string) bool {
- if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) {
- return false
- }
- return true
-}
diff --git a/internal/system/paths_test.go b/internal/system/paths_test.go
@@ -1,21 +0,0 @@
-package system_test
-
-import (
- "os"
- "path/filepath"
- "testing"
-
- "github.com/enckse/lockbox/internal/system"
-)
-
-func TestPathExist(t *testing.T) {
- testDir := filepath.Join("testdata", "exists")
- os.RemoveAll(testDir)
- if system.PathExists(testDir) {
- t.Error("test dir SHOULD NOT exist")
- }
- os.MkdirAll(testDir, 0o755)
- if !system.PathExists(testDir) {
- t.Error("test dir SHOULD exist")
- }
-}