-
-
Notifications
You must be signed in to change notification settings - Fork 602
Description
Is there an existing issue for this?
- I have searched the existing issues
What happened?
When a user deletes a folder through Settings → Folder Management, the thumbnail image files on disk are never cleaned up. The SQL ON DELETE CASCADE removes the image records from the database, but the physical thumbnail_*.jpg files in the app's thumbnail directory remain on disk permanently. This causes a silent disk space leak that grows every time a folder is removed.
Expected Behavior
When a folder is deleted, all associated thumbnail files on disk should also be removed. The delete_folders route should query all thumbnail paths for images belonging to the folders being deleted before removing the DB records, and then delete those files from disk.
Root Cause
The delete_folders route in backend/app/routes/folders.py only calls the database batch delete function which performs a SQL DELETE — it never touches the filesystem to remove the corresponding thumbnail files.
Interestingly, the sync/obsolete flow in backend/app/utils/images.py (image_util_remove_obsolete_images) does correctly clean up thumbnails when images are found to be missing from the filesystem — but this function is never called during the folder deletion flow.
The same problem also exists in folder_util_delete_obsolete_folders in backend/app/utils/folders.py — it deletes folder records from the database without any thumbnail cleanup.
Steps to Reproduce
- Open PictoPy and add a folder containing images (e.g., 50 photos).
- Wait for processing to complete (thumbnails generated).
- Note the files in the thumbnails directory (
~/.local/share/PictoPy/thumbnails/). - Go to Settings → Folder Management and delete the folder.
- Check the thumbnails directory again — all thumbnail files from step 3 are still present.
- Repeat steps 1–5 — orphan files keep accumulating.
Notes
- Each thumbnail is a JPEG up to 600×600px (typically 20–100 KB each).
- A user adding/removing 10 folders of 500 photos = ~5,000 orphaned thumbnails = ~100–500 MB leaked.
- Users have no way to identify or clean these orphaned files without manually inspecting the directory.
- This is related to but distinct from BUG: face data persists after source folder is removed #569 (face data persistence) and BUG:Images skipped silently when thumbnail generation fails #843 (thumbnail generation failure). Neither of those issues covers orphan thumbnail cleanup on folder deletion.
Files Involved
backend/app/routes/folders.py—delete_folders()(primary fix needed)backend/app/utils/folders.py—folder_util_delete_obsolete_folders()(also needs fix)backend/app/database/images.py—db_get_images_by_folder_ids()(needed to query thumbnails before deletion)backend/app/utils/images.py—image_util_remove_obsolete_images()(reference for correct thumbnail cleanup)
Record
- I agree to follow this project's Code of Conduct
Record
- I agree to follow this project's Code of Conduct