mirror of
https://github.com/stashapp/stash.git
synced 2026-05-08 20:58:48 +02:00
Remove empty directories on Clean Generated Files with Blobs (#6749)
This commit is contained in:
parent
083ba25d04
commit
0b811e13b9
1 changed files with 31 additions and 0 deletions
|
|
@ -313,9 +313,36 @@ func (j *CleanGeneratedJob) cleanBlobFiles(ctx context.Context, progress *job.Pr
|
|||
return err
|
||||
}
|
||||
|
||||
// remove empty hash prefix subdirectories
|
||||
j.removeEmptyDirs(j.Paths.Blobs)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j *CleanGeneratedJob) removeEmptyDirs(root string) {
|
||||
entries, err := os.ReadDir(root)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
dirPath := filepath.Join(root, entry.Name())
|
||||
subEntries, err := os.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(subEntries) == 0 {
|
||||
j.logDelete("removing empty directory: %s", entry.Name())
|
||||
j.deleteDir(dirPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (j *CleanGeneratedJob) getScenesWithHash(ctx context.Context, hash string) ([]*models.Scene, error) {
|
||||
fp := models.Fingerprint{
|
||||
Fingerprint: hash,
|
||||
|
|
@ -637,6 +664,8 @@ func (j *CleanGeneratedJob) cleanMarkerFiles(ctx context.Context, progress *job.
|
|||
return err
|
||||
}
|
||||
|
||||
j.removeEmptyDirs(j.Paths.Generated.Markers)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -730,5 +759,7 @@ func (j *CleanGeneratedJob) cleanThumbnailFiles(ctx context.Context, progress *j
|
|||
return err
|
||||
}
|
||||
|
||||
j.removeEmptyDirs(j.Paths.Generated.Thumbnails)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue