From d83ede2b04f885fb5a2eb6d03ad0d18b7d0cd5cd Mon Sep 17 00:00:00 2001 From: Dominik Schulz Date: Mon, 20 Mar 2017 14:16:17 +0100 Subject: [PATCH] Improve recusrive deletes This commit improves handling of 'rm -r' on files as well as removing empty dirs. Fixes #55 Fixes #70 --- password/git.go | 3 +++ password/store.go | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/password/git.go b/password/git.go index a70d952153..1c2f328d4d 100644 --- a/password/git.go +++ b/password/git.go @@ -134,6 +134,9 @@ func (s *Store) gitAdd(files ...string) error { if !s.isGit() { return ErrGitNotInit } + for i := range files { + files[i] = strings.TrimPrefix(files[i], s.path+"/") + } args := []string{"add", "--all"} args = append(args, files...) diff --git a/password/store.go b/password/store.go index 7ff01e9c39..a9aa1ef303 100644 --- a/password/store.go +++ b/password/store.go @@ -400,16 +400,17 @@ func (s *Store) Prune(tree string) error { func (s *Store) delete(name string, recurse bool) error { path := s.passfile(name) rf := os.Remove - if recurse { - path = filepath.Join(s.path, name) - rf = os.RemoveAll - } if !recurse && !fsutil.IsFile(path) { return ErrNotFound } - if recurse && !fsutil.IsDir(path) { - return ErrNotFound + + if recurse && !fsutil.IsFile(path) { + path = filepath.Join(s.path, name) + rf = os.RemoveAll + if !fsutil.IsDir(path) { + return ErrNotFound + } } if err := rf(path); err != nil {