Skip to content

Commit

Permalink
Also empty the dabatase when emptying the trash
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Jul 19, 2021
1 parent c0ff3ec commit 35b26e8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkg/storage/fs/owncloudsql/filecache/filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,22 @@ func (c *Cache) GetRecycleItem(user, path string, timestamp int) (*TrashItem, er
}, nil
}

// EmptyRecycle clears the recycle bin for the given user
func (c *Cache) EmptyRecycle(user string) error {
_, err := c.db.Exec("DELETE FROM oc_files_trash WHERE user = ?", user)
if err != nil {
return err
}

storage, err := c.GetNumericStorageID("home::" + user)
if err != nil {
return err
}

_, err = c.db.Exec("DELETE FROM oc_filecache WHERE storage = ? AND PATH LIKE ?", storage, "files_trashbin/%")
return err
}

// DeleteRecycleItem deletes the specified item from the trash
func (c *Cache) DeleteRecycleItem(user, path string, timestamp int) error {
_, err := c.db.Exec("DELETE FROM oc_files_trash WHERE id = ? AND user = ? AND timestamp = ?", path, user, timestamp)
Expand Down
16 changes: 15 additions & 1 deletion pkg/storage/fs/owncloudsql/filecache/filecache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,20 @@ var _ = Describe("Filecache", func() {
})
})

Describe("PurgeRecycleItem", func() {
Describe("EmptyRecycle", func() {
It("clears the recycle bin", func() {
err := cache.Delete(1, "admin", filePath, trashPath)
Expect(err).ToNot(HaveOccurred())

err = cache.EmptyRecycle("admin")
Expect(err).ToNot(HaveOccurred())

_, err = cache.GetRecycleItem("admin", trashPathBase, trashPathTimestamp)
Expect(err).To(HaveOccurred())
})
})

Describe("DeleteRecycleItem", func() {
It("removes the item from the trash", func() {
err := cache.Delete(1, "admin", filePath, trashPath)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -461,6 +474,7 @@ var _ = Describe("Filecache", func() {
Expect(err).ToNot(HaveOccurred())
})
})

Describe("PurgeRecycleItem", func() {
It("removes the item from the database", func() {
err := cache.Delete(1, "admin", filePath, trashPath)
Expand Down
6 changes: 6 additions & 0 deletions pkg/storage/fs/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,12 @@ func (fs *ocfs) EmptyRecycle(ctx context.Context) error {
if err != nil {
return errors.Wrap(err, "owncloudsql: error deleting recycle files versions")
}

err = fs.filecache.EmptyRecycle()
if err != nil {
return errors.Wrap(err, "owncloudsql: error deleting recycle items from the database")
}

// TODO delete keyfiles, keys, share-keys ... or just everything?
return nil
}
Expand Down

0 comments on commit 35b26e8

Please sign in to comment.