Skip to content

[BUG] Orphaned files remain in screenly_assets folder after asset deletion #2657

@nicomiguelino

Description

@nicomiguelino

Description

When assets are deleted through the web interface, orphaned files remain in the screenly_assets folder. The asset deletion process only removes the main file referenced in the database (asset.uri) but doesn't clean up temporary or related files that may have been created during upload, processing, or background operations.

Steps to Reproduce

  1. Create multiple video assets (MP4 files) in Anthias
  2. Delete all assets except one through the web interface
  3. SSH into the device and check the screenly_assets folder: ls ~/screenly_assets
  4. Observe that more files exist than expected (should be 1 file, but multiple files remain)

Expected Behavior

When an asset is deleted through the web interface, all associated files should be removed from the screenly_assets folder, leaving only files for active assets.

Root Cause

The deletion logic in api/views/mixins.py:34-45 (DeleteAssetViewMixin.delete()) only removes the file at asset.uri. It doesn't clean up:

  • Temporary files from incomplete or failed uploads
  • Files created during chunked upload processes that were renamed from .tmp to final format
  • Files from YouTube downloads that completed in background after asset deletion
  • Orphaned files from interrupted operations

The hourly cleanup task in celery_tasks.py:60-67 only removes .tmp files, but doesn't catch files that were already renamed to their final format (e.g., .mp4) before the asset creation failed.

Affected Code

  • api/views/mixins.py - DeleteAssetViewMixin (lines 31-45)
  • api/views/mixins.py - FileAssetViewMixin (lines 138-189) - chunked upload handling
  • api/serializers/mixins.py - file renaming during asset creation (lines 52-57)
  • lib/utils.py - YoutubeDownloadThread (lines 415-443) - background downloads
  • celery_tasks.py - cleanup task (lines 60-67)

Proposed Solution

  1. Track all temporary files associated with an asset (possibly in Redis or a temporary table)
  2. Enhance DeleteAssetViewMixin to find and delete all files related to an asset, not just asset.uri
  3. Implement cleanup for orphaned files from failed YouTube downloads
  4. Improve the periodic cleanup task to identify and remove orphaned files based on asset ID matching

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions