Skip to content
Permalink
Browse files

Move deleted entries to recycle bin

  • Loading branch information...
Raggaer committed Feb 21, 2019
1 parent f144b5c commit 1dacbcecc82e552a83b9f5c5c0ffd05ef2cbafc1
Showing with 26 additions and 0 deletions.
  1. +26 −0 entry.go
@@ -11,6 +11,8 @@ import (
"github.com/tobischo/gokeepasslib/v2"
)

const recycleBinGroup = "Recycle Bin"

type newEntryForm struct {
Title string
URL string
@@ -42,13 +44,37 @@ func deleteEntry(entry *gokeepasslib.Entry) bool {
g := currentGroup()
for k, e := range g.Entries {
if e.UUID.Compare(entry.UUID) {
// Delete entry from the current group
g.Entries = append(g.Entries[:k], g.Entries[k+1:]...)

// Add entry to recycle bin
if g.Name != recycleBinGroup {
moveEntryToRecycleBin(entry)
}
return true
}
}
return false
}

func moveEntryToRecycleBin(entry *gokeepasslib.Entry) {
// Recycle bin group is at the root, if it does not exist we create it
for i, g := range database.Content.Root.Groups[0].Groups {
if g.Name == recycleBinGroup {
e := gokeepasslib.NewEntry()
e.Values = append(entry.Values, gokeepasslib.ValueData{Key: "UserName", Value: gokeepasslib.V{Content: entry.GetContent("UserName")}})
e.Values = append(entry.Values, gokeepasslib.ValueData{Key: "Title", Value: gokeepasslib.V{Content: entry.GetTitle()}})
e.Values = append(entry.Values, gokeepasslib.ValueData{Key: "URL", Value: gokeepasslib.V{Content: entry.GetContent("URL")}})
e.Values = append(entry.Values, gokeepasslib.ValueData{Key: "Password", Value: gokeepasslib.V{Content: entry.GetPassword(), Protected: true}})
database.Content.Root.Groups[0].Groups[i].Entries = append(database.Content.Root.Groups[0].Groups[i].Entries, e)
return
}
}
bin := gokeepasslib.NewGroup()
bin.Name = recycleBinGroup
database.Content.Root.Groups[0].Groups = append(database.Content.Root.Groups[0].Groups, bin)
}

// Command "search" searches for entries of the current group
func search(args []string) {
// We combine args again to allow spaces

0 comments on commit 1dacbce

Please sign in to comment.
You can’t perform that action at this time.