cScan Safety Assessment Fixes
Issue Identified
The safety assessment was being too aggressive and marking all files as “critical”, preventing any deletions.
Root Causes
- Overly broad critical path matching: Using substring matching (
if any(critical in filepath for critical in self.critical_paths)) was catching too many files - Running process protection too aggressive: Every directory containing a running executable was marked as critical
- File-in-use check failing: Non-existent test files were being marked as “in use”
Fixes Applied
1. Improved Critical Path Detection
- Changed from substring matching to proper path prefix matching
- Only protect actual Windows system directories, not all user app directories
- Removed overly broad Microsoft folder protection in user space
# Before: if any(critical in filepath for critical in self.critical_paths)
# After: Proper startswith() check on normalized paths
for critical_path in self.critical_paths:
if path_lower.startswith(critical_path):
return 'critical'
2. Smarter Running Process Protection
- Only protect executables in actual system directories
- Don’t mark entire app directories as critical just because an app is running
3. Better Safety Categorization
- More specific patterns for safe files (cache, temp, crashdumps)
- Added specific safe locations (pip cache, npm cache, game caches)
- Proper path separators in patterns to avoid false matches
4. Fixed File-in-Use Detection
- Check if file exists before trying to open it
- Better error handling to distinguish between “file not found” and “file locked”
5. Enhanced File Categorization
- Separated .exe files into appropriate categories (installers vs system vs executables)
- Added crashdumps as a separate category
- Better handling of files without extensions
6. Improved Smart Suggestions
- Prioritize safe deletions (cache files, old temp files)
- Sort suggestions by safety level and size
- More categories: crashdumps, old installers, large media files
7. Added Safety Controls
dry_run_mode: Test what would be deleted without actually deletingoverride_safety: Allow advanced users to override safety checks (dangerous!)use_recycle_bin: Send to recycle bin instead of permanent deletion (default: true)
Result
The safety assessment now correctly identifies:
- [SAFE] Safe files: Cache, temp, crashdumps in appropriate locations
- [USER] User files: Downloads, documents, media files requiring confirmation
- [UNKN] Unknown files: Files that don’t match clear patterns
- [CRIT] Critical files: True system files and actively used files
Files are no longer incorrectly marked as critical, while still protecting important system files and data.