fix: handle errors when attempting to delete associated shares
parent
49698b3df0
commit
35950369ef
|
@ -73,7 +73,10 @@ func resourceDeleteHandler(fileCache FileCache) handleFunc {
|
|||
return errToStatus(err), err
|
||||
}
|
||||
|
||||
d.store.Share.DeleteWithPathPrefix(file.Path)
|
||||
err = d.store.Share.DeleteWithPathPrefix(file.Path)
|
||||
if err != nil {
|
||||
fmt.Println("Warning: Error(s) occurred while deleting associated shares with file:" + err.Error())
|
||||
}
|
||||
|
||||
// delete thumbnails
|
||||
err = delThumbs(r.Context(), fileCache, file)
|
||||
|
|
|
@ -15,7 +15,7 @@ type StorageBackend interface {
|
|||
Gets(path string, id uint) ([]*Link, error)
|
||||
Save(s *Link) error
|
||||
Delete(hash string) error
|
||||
DeleteWithPathPrefix(path string)
|
||||
DeleteWithPathPrefix(path string) error
|
||||
}
|
||||
|
||||
// Storage is a storage.
|
||||
|
@ -120,6 +120,6 @@ func (s *Storage) Delete(hash string) error {
|
|||
return s.back.Delete(hash)
|
||||
}
|
||||
|
||||
func (s *Storage) DeleteWithPathPrefix(path string) {
|
||||
s.back.DeleteWithPathPrefix(path)
|
||||
func (s *Storage) DeleteWithPathPrefix(path string) error {
|
||||
return s.back.DeleteWithPathPrefix(path)
|
||||
}
|
||||
|
|
|
@ -76,10 +76,16 @@ func (s shareBackend) Delete(hash string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (s shareBackend) DeleteWithPathPrefix(pathPrefix string) {
|
||||
func (s shareBackend) DeleteWithPathPrefix(pathPrefix string) error {
|
||||
var links []share.Link
|
||||
s.db.Prefix("Path", pathPrefix, &links)
|
||||
for _, link := range links {
|
||||
s.db.DeleteStruct(&share.Link{Hash: link.Hash})
|
||||
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…
Reference in New Issue