mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-07-04 07:02:58 +00:00
fix: remove associated shares when deleting file/folder
This commit is contained in:
parent
47b3e218ad
commit
e99e0b3028
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -73,6 +74,11 @@ func resourceDeleteHandler(fileCache FileCache) handleFunc {
|
||||
return errToStatus(err), err
|
||||
}
|
||||
|
||||
err = d.store.Share.DeleteWithPathPrefix(file.Path)
|
||||
if err != nil {
|
||||
log.Printf("WARNING: Error(s) occurred while deleting associated shares with file: %s", err)
|
||||
}
|
||||
|
||||
// delete thumbnails
|
||||
err = delThumbs(r.Context(), fileCache, file)
|
||||
if err != nil {
|
||||
|
@ -15,6 +15,7 @@ type StorageBackend interface {
|
||||
Gets(path string, id uint) ([]*Link, error)
|
||||
Save(s *Link) error
|
||||
Delete(hash string) error
|
||||
DeleteWithPathPrefix(path string) error
|
||||
}
|
||||
|
||||
// Storage is a storage.
|
||||
@ -118,3 +119,7 @@ func (s *Storage) Save(l *Link) error {
|
||||
func (s *Storage) Delete(hash string) error {
|
||||
return s.back.Delete(hash)
|
||||
}
|
||||
|
||||
func (s *Storage) DeleteWithPathPrefix(path string) error {
|
||||
return s.back.DeleteWithPathPrefix(path)
|
||||
}
|
||||
|
@ -75,3 +75,16 @@ func (s shareBackend) Delete(hash string) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s shareBackend) DeleteWithPathPrefix(pathPrefix string) error {
|
||||
var links []share.Link
|
||||
if err := s.db.Prefix("Path", pathPrefix, &links); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var err error
|
||||
for _, link := range links {
|
||||
err = errors.Join(err, s.db.DeleteStruct(&share.Link{Hash: link.Hash}))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user