Skip to content

Commit

Permalink
lib/db: Properly remove FileInfos when dropping folder (syncthing#5260)
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh authored and imsodin committed Oct 11, 2018
1 parent 3e50edf commit 3bc918f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/db/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (db *instance) withAllFolderTruncated(folder []byte, fn func(device []byte,
t := db.newReadWriteTransaction()
defer t.close()

dbi := t.NewIterator(util.BytesPrefix(db.keyer.GenerateDeviceFileKey(nil, folder, nil, nil).WithoutName()), nil)
dbi := t.NewIterator(util.BytesPrefix(db.keyer.GenerateDeviceFileKey(nil, folder, nil, nil).WithoutNameAndDevice()), nil)
defer dbi.Release()

var gk []byte
Expand Down Expand Up @@ -439,7 +439,7 @@ func (db *instance) dropFolder(folder []byte) {

for _, key := range [][]byte{
// Remove all items related to the given folder from the device->file bucket
db.keyer.GenerateDeviceFileKey(nil, folder, nil, nil).WithoutName(),
db.keyer.GenerateDeviceFileKey(nil, folder, nil, nil).WithoutNameAndDevice(),
// Remove all sequences related to the folder
db.keyer.GenerateSequenceKey(nil, []byte(folder), 0).WithoutSequence(),
// Remove all items related to the given folder from the global bucket
Expand Down
4 changes: 2 additions & 2 deletions lib/db/keyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func newDefaultKeyer(folderIdx, deviceIdx *smallIndex) defaultKeyer {

type deviceFileKey []byte

func (k deviceFileKey) WithoutName() []byte {
return k[:keyPrefixLen+keyFolderLen+keyDeviceLen]
func (k deviceFileKey) WithoutNameAndDevice() []byte {
return k[:keyPrefixLen+keyFolderLen]
}

func (k defaultKeyer) GenerateDeviceFileKey(key, folder, device, name []byte) deviceFileKey {
Expand Down

0 comments on commit 3bc918f

Please sign in to comment.