From d292ed0b347147dba95cdd276375080c49e7b43c Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Mon, 25 Oct 2021 09:29:03 +1100 Subject: [PATCH] Fix deleting folder-based gallery file deleting (#1872) * Fix deleting gallery image files * Clarify delete file documentation --- graphql/schema/types/gallery.graphql | 5 +++++ pkg/api/resolver_mutation_gallery.go | 12 +++++++----- ui/v2.5/src/components/Changelog/versions/v0110.md | 1 + .../components/Galleries/DeleteGalleriesDialog.tsx | 4 +++- ui/v2.5/src/locales/en-GB.json | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/graphql/schema/types/gallery.graphql b/graphql/schema/types/gallery.graphql index 1c87a4b86..a06c6a512 100644 --- a/graphql/schema/types/gallery.graphql +++ b/graphql/schema/types/gallery.graphql @@ -74,6 +74,11 @@ input BulkGalleryUpdateInput { input GalleryDestroyInput { ids: [ID!]! + """ + If true, then the zip file will be deleted if the gallery is zip-file-based. + If gallery is folder-based, then any files not associated with other + galleries will be deleted, along with the folder, if it is not empty. + """ delete_file: Boolean delete_generated: Boolean } diff --git a/pkg/api/resolver_mutation_gallery.go b/pkg/api/resolver_mutation_gallery.go index 8b4259782..c9de9a940 100644 --- a/pkg/api/resolver_mutation_gallery.go +++ b/pkg/api/resolver_mutation_gallery.go @@ -441,7 +441,7 @@ func (r *mutationResolver) GalleryDestroy(ctx context.Context, input models.Gall return err } - if len(imgGalleries) == 0 { + if len(imgGalleries) == 1 { if err := iqb.Destroy(img.ID); err != nil { return err } @@ -465,13 +465,15 @@ func (r *mutationResolver) GalleryDestroy(ctx context.Context, input models.Gall // if delete file is true, then delete the file as well // if it fails, just log a message if input.DeleteFile != nil && *input.DeleteFile { - for _, gallery := range galleries { - manager.DeleteGalleryFile(gallery) - } - + // #1804 - delete the image files first, since they must be removed + // before deleting a folder for _, img := range imgsToDelete { manager.DeleteImageFile(img) } + + for _, gallery := range galleries { + manager.DeleteGalleryFile(gallery) + } } // if delete generated is true, then delete the generated files diff --git a/ui/v2.5/src/components/Changelog/versions/v0110.md b/ui/v2.5/src/components/Changelog/versions/v0110.md index e0aa193ca..9c3cb9987 100644 --- a/ui/v2.5/src/components/Changelog/versions/v0110.md +++ b/ui/v2.5/src/components/Changelog/versions/v0110.md @@ -11,6 +11,7 @@ * Optimised scanning process. ([#1816](https://github.com/stashapp/stash/pull/1816)) ### 🐛 Bug fixes +* Fix image files in folder galleries not being deleting when delete file option is checked. ([#1872](https://github.com/stashapp/stash/pull/1872)) * Fix marker generation task reading video files unnecessarily. ([#1871](https://github.com/stashapp/stash/pull/1871)) * Fix accessing Stash via IPv6 link local address causing security tripwire to be activated. ([#1841](https://github.com/stashapp/stash/pull/1841)) * Fix Twitter value defaulting to freeones in built-in Freeones scraper. ([#1853](https://github.com/stashapp/stash/pull/1853)) diff --git a/ui/v2.5/src/components/Galleries/DeleteGalleriesDialog.tsx b/ui/v2.5/src/components/Galleries/DeleteGalleriesDialog.tsx index 8ff227e5c..c786a2311 100644 --- a/ui/v2.5/src/components/Galleries/DeleteGalleriesDialog.tsx +++ b/ui/v2.5/src/components/Galleries/DeleteGalleriesDialog.tsx @@ -82,7 +82,9 @@ export const DeleteGalleriesDialog: React.FC = ( setDeleteFile(!deleteFile)} />