commit 327dc4cbe24803801b066cfe57352eb020978fb0
parent 26c8edcfd37768355b085ff6d18be7c60fd66811
Author: Sean Enck <sean@ttypty.com>
Date: Tue, 13 Sep 2022 19:12:43 -0400
misc no longer exists
Diffstat:
8 files changed, 21 insertions(+), 33 deletions(-)
diff --git a/cmd/main.go b/cmd/main.go
@@ -12,7 +12,6 @@ import (
"github.com/enckse/lockbox/internal/encrypt"
"github.com/enckse/lockbox/internal/hooks"
"github.com/enckse/lockbox/internal/inputs"
- "github.com/enckse/lockbox/internal/misc"
"github.com/enckse/lockbox/internal/platform"
"github.com/enckse/lockbox/internal/store"
"github.com/enckse/lockbox/internal/subcommands"
@@ -98,7 +97,7 @@ func main() {
}
isPipe := inputs.IsInputFromPipe()
entry := getEntry(store.NewFileSystemStore(), args, idx)
- if misc.PathExists(entry) {
+ if store.PathExists(entry) {
if !isPipe {
if !confirm("overwrite existing") {
return
@@ -106,7 +105,7 @@ func main() {
}
} else {
dir := filepath.Dir(entry)
- if !misc.PathExists(dir) {
+ if !store.PathExists(dir) {
if err := os.MkdirAll(dir, 0755); err != nil {
die("failed to create directory structure", err)
}
@@ -123,7 +122,7 @@ func main() {
hooks.Run(hooks.Insert, hooks.PostStep)
case "rm":
entry := getEntry(store.NewFileSystemStore(), args, 2)
- if !misc.PathExists(entry) {
+ if !store.PathExists(entry) {
die("does not exists", errors.New("can not delete unknown entry"))
}
if confirm("remove entry") {
diff --git a/internal/encrypt/core_test.go b/internal/encrypt/core_test.go
@@ -6,13 +6,13 @@ import (
"path/filepath"
"testing"
- "github.com/enckse/lockbox/internal/misc"
+ "github.com/enckse/lockbox/internal/store"
)
func setupData(t *testing.T) string {
os.Setenv("LOCKBOX_KEYMODE", "")
os.Setenv("LOCKBOX_KEY", "")
- if misc.PathExists("bin") {
+ if store.PathExists("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
@@ -8,7 +8,7 @@ import (
"path/filepath"
"github.com/enckse/lockbox/internal/inputs"
- "github.com/enckse/lockbox/internal/misc"
+ "github.com/enckse/lockbox/internal/store"
)
type (
@@ -30,7 +30,7 @@ const (
// Run executes any configured hooks.
func Run(action Action, step Step) error {
hookDir := os.Getenv(inputs.HooksDirEnv)
- if !misc.PathExists(hookDir) {
+ if !store.PathExists(hookDir) {
return nil
}
dirs, err := os.ReadDir(hookDir)
diff --git a/internal/misc/os.go b/internal/misc/os.go
@@ -1,16 +0,0 @@
-// Package misc handles os operations.
-package misc
-
-import (
- "os"
-)
-
-// PathExists indicates if a path exists.
-func PathExists(path string) bool {
- if _, err := os.Stat(path); err != nil {
- if os.IsNotExist(err) {
- return false
- }
- }
- return true
-}
diff --git a/internal/store/filesystem.go b/internal/store/filesystem.go
@@ -10,7 +10,6 @@ import (
"strings"
"github.com/enckse/lockbox/internal/inputs"
- "github.com/enckse/lockbox/internal/misc"
)
const (
@@ -40,7 +39,7 @@ func NewFileSystemStore() FileSystem {
// List will get all lockbox files in a store.
func (s FileSystem) List(options ViewOptions) ([]string, error) {
var results []string
- if !misc.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 {
@@ -98,3 +97,13 @@ func (s FileSystem) trim(path string) string {
f = strings.TrimPrefix(f, string(os.PathSeparator))
return strings.TrimSuffix(f, extension)
}
+
+// PathExists indicates if a path exists.
+func PathExists(path string) bool {
+ if _, err := os.Stat(path); err != nil {
+ if os.IsNotExist(err) {
+ return false
+ }
+ }
+ return true
+}
diff --git a/internal/store/filesystem_test.go b/internal/store/filesystem_test.go
@@ -6,8 +6,6 @@ import (
"path/filepath"
"strings"
"testing"
-
- "github.com/enckse/lockbox/internal/misc"
)
func TestListErrors(t *testing.T) {
@@ -19,7 +17,7 @@ func TestListErrors(t *testing.T) {
func TestList(t *testing.T) {
testStore := "bin"
- if misc.PathExists(testStore) {
+ if PathExists(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
@@ -11,7 +11,6 @@ import (
"github.com/enckse/lockbox/internal/colors"
"github.com/enckse/lockbox/internal/dump"
"github.com/enckse/lockbox/internal/encrypt"
- "github.com/enckse/lockbox/internal/misc"
"github.com/enckse/lockbox/internal/store"
)
@@ -57,7 +56,7 @@ func DisplayCallback(args DisplayOptions) ([]dump.ExportEntity, error) {
}
dumpData := []dump.ExportEntity{}
for _, entry := range entries {
- if !misc.PathExists(entry) {
+ if !store.PathExists(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
@@ -16,7 +16,6 @@ import (
"github.com/enckse/lockbox/internal/colors"
"github.com/enckse/lockbox/internal/encrypt"
"github.com/enckse/lockbox/internal/inputs"
- "github.com/enckse/lockbox/internal/misc"
"github.com/enckse/lockbox/internal/platform"
"github.com/enckse/lockbox/internal/store"
otp "github.com/pquerna/otp/totp"
@@ -96,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 !misc.PathExists(pathing) {
+ if !store.PathExists(pathing) {
return errors.New("object does not exist")
}
val, err := encrypt.FromFile(pathing)