diff --git a/pkg/file/delete.go b/pkg/file/delete.go index b667aca6f..badbb5096 100644 --- a/pkg/file/delete.go +++ b/pkg/file/delete.go @@ -181,7 +181,7 @@ func Destroy(ctx context.Context, destroyer Destroyer, f File, fileDeleter *Dele } // don't delete files in zip files - if deleteFile && f.Base().ZipFileID != nil { + if deleteFile && f.Base().ZipFileID == nil { if err := fileDeleter.Files([]string{f.Base().Path}); err != nil { return err } @@ -190,17 +190,24 @@ func Destroy(ctx context.Context, destroyer Destroyer, f File, fileDeleter *Dele return nil } -type FolderGetterDestroyer interface { - FolderGetter - FolderDestroyer -} - type ZipDestroyer struct { - FileDestroyer Destroyer + FileDestroyer GetterDestroyer FolderDestroyer FolderGetterDestroyer } func (d *ZipDestroyer) DestroyZip(ctx context.Context, f File, fileDeleter *Deleter, deleteFile bool) error { + // destroy contained files + files, err := d.FileDestroyer.FindByZipFileID(ctx, f.Base().ID) + if err != nil { + return err + } + + for _, ff := range files { + if err := d.FileDestroyer.Destroy(ctx, ff.Base().ID); err != nil { + return err + } + } + // destroy contained folders folders, err := d.FolderDestroyer.FindByZipFileID(ctx, f.Base().ID) if err != nil { diff --git a/pkg/file/file.go b/pkg/file/file.go index d618a2e5f..3b83e4946 100644 --- a/pkg/file/file.go +++ b/pkg/file/file.go @@ -177,6 +177,11 @@ type Destroyer interface { Destroy(ctx context.Context, id ID) error } +type GetterDestroyer interface { + Getter + Destroyer +} + // Store provides methods to find, create and update Files. type Store interface { Getter diff --git a/pkg/file/folder.go b/pkg/file/folder.go index 9675afce2..2eb4edd12 100644 --- a/pkg/file/folder.go +++ b/pkg/file/folder.go @@ -56,6 +56,11 @@ type FolderDestroyer interface { Destroy(ctx context.Context, id FolderID) error } +type FolderGetterDestroyer interface { + FolderGetter + FolderDestroyer +} + // FolderStore provides methods to find, create and update Folders. type FolderStore interface { FolderGetter diff --git a/ui/v2.5/src/components/Galleries/DeleteGalleriesDialog.tsx b/ui/v2.5/src/components/Galleries/DeleteGalleriesDialog.tsx index eedabfc17..4e128dd28 100644 --- a/ui/v2.5/src/components/Galleries/DeleteGalleriesDialog.tsx +++ b/ui/v2.5/src/components/Galleries/DeleteGalleriesDialog.tsx @@ -7,7 +7,6 @@ import { useToast } from "src/hooks"; import { ConfigurationContext } from "src/hooks/Config"; import { FormattedMessage, useIntl } from "react-intl"; import { faTrashAlt } from "@fortawesome/free-solid-svg-icons"; -import { galleryPath } from "src/core/galleries"; interface IDeleteGalleryDialogProps { selected: GQL.SlimGalleryDataFragment[]; @@ -74,8 +73,14 @@ export const DeleteGalleriesDialog: React.FC = ( return; } - const fsGalleries = props.selected.filter((g) => galleryPath(g)); - if (fsGalleries.length === 0) { + const deletedFiles: string[] = []; + + props.selected.forEach((s) => { + const paths = s.files.map((f) => f.path); + deletedFiles.push(...paths); + }); + + if (deletedFiles.length === 0) { return; } @@ -84,7 +89,7 @@ export const DeleteGalleriesDialog: React.FC = (

= ( />