commit 7f64666c41a9e2f2dd46b154b43c903dca864004
parent 9082d328466f619859f4583bd5434a4cdd92335f
Author: Sean Enck <sean@ttypty.com>
Date: Fri, 30 Sep 2022 20:15:14 -0400
shift to call the storage wrapper for this
Diffstat:
8 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/cmd/main.go b/cmd/main.go
@@ -117,7 +117,7 @@ func run() *programError {
isPipe := inputs.IsInputFromPipe()
s := store.NewFileSystemStore()
entry := getEntry(s, args, idx)
- if store.PathExists(entry) {
+ if s.Exists(entry) {
if !isPipe {
if !confirm("overwrite existing") {
return nil
@@ -125,7 +125,7 @@ func run() *programError {
}
} else {
dir := filepath.Dir(entry)
- if !store.PathExists(dir) {
+ if !s.Exists(dir) {
if err := os.MkdirAll(dir, 0755); err != nil {
return newError("failed to create directory structure", err)
}
@@ -165,7 +165,7 @@ func run() *programError {
}
if confirm(fmt.Sprintf("remove %s", confirmText)) {
for _, entry := range deletes {
- if !store.PathExists(entry) {
+ if !s.Exists(entry) {
return newError("does not exists", errors.New("can not delete unknown entry"))
}
}
diff --git a/cmd/vers.txt b/cmd/vers.txt
@@ -1 +1 @@
-v22.09.05
+v22.09.06
diff --git a/internal/encrypt/core_test.go b/internal/encrypt/core_test.go
@@ -14,7 +14,7 @@ import (
func setupData(t *testing.T) string {
os.Setenv("LOCKBOX_KEYMODE", "")
os.Setenv("LOCKBOX_KEY", "")
- if store.PathExists("bin") {
+ if store.NewFileSystemStore().Exists("bin") {
if err := os.RemoveAll("bin"); err != nil {
t.Errorf("unable to cleanup dir: %v", err)
}
diff --git a/internal/hooks/execute.go b/internal/hooks/execute.go
@@ -30,7 +30,7 @@ const (
// Run executes any configured hooks.
func Run(action Action, step Step) error {
hookDir := os.Getenv(inputs.HooksDirEnv)
- if !store.PathExists(hookDir) {
+ if !store.NewFileSystemStore().Exists(hookDir) {
return nil
}
dirs, err := os.ReadDir(hookDir)
diff --git a/internal/store/filesystem.go b/internal/store/filesystem.go
@@ -46,7 +46,7 @@ func (s FileSystem) Globs(inputPath string) ([]string, error) {
// List will get all lockbox files in a store.
func (s FileSystem) List(options ViewOptions) ([]string, error) {
var results []string
- if !PathExists(s.path) {
+ if !pathExists(s.path) {
return nil, errors.New("store does not exist")
}
err := filepath.Walk(s.path, func(path string, info fs.FileInfo, err error) error {
@@ -105,8 +105,13 @@ func (s FileSystem) trim(path string) string {
return strings.TrimSuffix(f, extension)
}
-// PathExists indicates if a path exists.
-func PathExists(path string) bool {
+// Exists will check if a path exists
+func (s FileSystem) Exists(path string) bool {
+ return pathExists(path)
+}
+
+// pathExists indicates if a path exists.
+func pathExists(path string) bool {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return false
@@ -133,7 +138,7 @@ func (s FileSystem) gitAction(action string, entries []string) error {
if !ok {
return nil
}
- if !PathExists(filepath.Join(s.path, ".git")) {
+ if !pathExists(filepath.Join(s.path, ".git")) {
return nil
}
var message []string
diff --git a/internal/store/filesystem_test.go b/internal/store/filesystem_test.go
@@ -21,7 +21,7 @@ func TestListErrors(t *testing.T) {
func TestList(t *testing.T) {
testStore := "bin"
- if store.PathExists(testStore) {
+ if store.NewFileSystemStore().Exists(testStore) {
if err := os.RemoveAll(testStore); err != nil {
t.Errorf("invalid error on remove: %v", err)
}
diff --git a/internal/subcommands/display.go b/internal/subcommands/display.go
@@ -57,7 +57,7 @@ func DisplayCallback(args DisplayOptions) ([]dump.ExportEntity, error) {
}
dumpData := []dump.ExportEntity{}
for _, entry := range entries {
- if !store.PathExists(entry) {
+ if !args.Store.Exists(entry) {
return nil, errors.New("entry not found")
}
decrypt, err := encrypt.FromFile(entry)
diff --git a/internal/subcommands/totp.go b/internal/subcommands/totp.go
@@ -95,7 +95,7 @@ func display(token string, args cli.Arguments) error {
f := store.NewFileSystemStore()
tok := filepath.Join(strings.TrimSpace(token), totpEnv())
pathing := f.NewPath(tok)
- if !store.PathExists(pathing) {
+ if !f.Exists(pathing) {
return errors.New("object does not exist")
}
val, err := encrypt.FromFile(pathing)