-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Include Private Storage in Orphan File Scanning for filer_check Command #1518
base: master
Are you sure you want to change the base?
Conversation
Integration of the suggestion from the community and sourcery-ai
…_ensure_safe_length
Issues: Management command filer_check does not find orphaned files in the private storage django-cms#1514
Reviewer's Guide by SourceryThis pull request modifies the Sequence diagram for filer_check command with orphaned files in private storagesequenceDiagram
participant User
participant Command
participant Storage
participant Database
User->>Command: Run filer_check --orphans
activate Command
Command->>Command: Iterate through FILER_STORAGES (public, private, ...)
Command->>Storage: listdir(UPLOAD_TO_PREFIX) for each storage
activate Storage
Storage-->>Command: Returns list of files
deactivate Storage
loop For each file in storage
Command->>Database: Check if file exists in File model
activate Database
Database-->>Command: Returns True/False
deactivate Database
alt File does not exist in database (orphan)
Command->>Command: Identify as orphan
Command->>User: Output orphaned file path
end
end
deactivate Command
Sequence diagram for filer_check command with delete orphaned files in private storagesequenceDiagram
participant User
participant Command
participant Storage
participant Database
User->>Command: Run filer_check --orphans --delete-orphans
activate Command
Command->>Command: Iterate through FILER_STORAGES (public, private, ...)
Command->>Storage: listdir(UPLOAD_TO_PREFIX) for each storage
activate Storage
Storage-->>Command: Returns list of files
deactivate Storage
loop For each file in storage
Command->>Database: Check if file exists in File model
activate Database
Database-->>Command: Returns True/False
deactivate Database
alt File does not exist in database (orphan)
Command->>Storage: delete(file)
activate Storage
Storage-->>Command: File deleted
deactivate Storage
Command->>User: Output deleted file path
end
end
deactivate Command
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Baraff24 - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider extracting the storage walking logic into a separate function or class to improve readability and maintainability.
- The verbosity handling could be more consistent across the different checks (orphans, missing files, image dimensions).
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟡 Testing: 2 issues found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@Baraff24 Thank for your contribution. Please have a look at the failing tests and fix those. Also, have a look at the suggestion by sourcery once, They do give useful and pragmatic suggestions sometimes. |
This pull request addresses an issue where the
filer_check
management command was only scanning the public media directory for orphaned files, ignoring the private storage (used for secure downloads). With this fix, the command now iterates through all storages configured inFILER_STORAGES
—including private storage—and correctly detects orphaned files.Changes include:
Related resources
Checklist
master
Summary by Sourcery
Extends the filer_check command to scan all configured storages for orphaned files, including private storage, and adds tests to verify the detection and removal of orphaned files in private storage.
Bug Fixes:
Tests: