mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-07-04 15:12:59 +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"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -73,6 +74,11 @@ func resourceDeleteHandler(fileCache FileCache) handleFunc {
|
|||||||
return errToStatus(err), err
|
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
|
// delete thumbnails
|
||||||
err = delThumbs(r.Context(), fileCache, file)
|
err = delThumbs(r.Context(), fileCache, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -15,6 +15,7 @@ type StorageBackend interface {
|
|||||||
Gets(path string, id uint) ([]*Link, error)
|
Gets(path string, id uint) ([]*Link, error)
|
||||||
Save(s *Link) error
|
Save(s *Link) error
|
||||||
Delete(hash string) error
|
Delete(hash string) error
|
||||||
|
DeleteWithPathPrefix(path string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storage is a storage.
|
// Storage is a storage.
|
||||||
@ -118,3 +119,7 @@ func (s *Storage) Save(l *Link) error {
|
|||||||
func (s *Storage) Delete(hash string) error {
|
func (s *Storage) Delete(hash string) error {
|
||||||
return s.back.Delete(hash)
|
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
|
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