Correctly delete files when specified (#2804)

This commit is contained in:
WithoutPants
2022-08-08 10:48:02 +10:00
parent 5843fdcecc
commit c825cf5d09
6 changed files with 50 additions and 22 deletions

View File

@@ -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 {