ITADN

Misleading "non existent" error for permission-denied files

#377Opentrkaplan 创建于 2025-12-14
T
trkaplancommented
**Is your feature request related to a problem? Please describe.** When trying to trash a file that exists but cannot be accessed (e.g., permission denied), the error message says "cannot trash non existent 'filename'" which is misleading. The file does exist, but the user lacks permission to access it. This happens because `describer.py` uses `fs.exists(path)` which returns `False` for files the user cannot stat due to permission issues, even though the file actually exists. **Describe the solution you'd like** Improve the `describe()` method in `trashcli/put/describer.py` to distinguish between: - Truly non-existent files → "non existent" - Files that exist but cannot be accessed → "not accessible" or "permission denied" This could be done by catching `PermissionError` or `OSError` when checking file existence: ```python elif not self.fs.exists(path): try: self.fs.lstat(path) # or os.lstat return 'not accessible' except FileNotFoundError: return 'non existent' except PermissionError: return 'not accessible' ``` **Describe alternatives you've considered** - Using `os.path.lexists()` which returns `True` for broken symlinks and may handle some edge cases - Wrapping the entire describe logic in try/except to catch permission errors at any point - Adding a new return option like "access denied" or "permission denied" for clarity **Additional context** To reproduce (as non-root user): ```bash sudo touch /tmp/root-test-file sudo chmod 600 /tmp/root-test-file # Now as regular user: trash-put /tmp/root-test-file ``` Current behavior: ``` $ trash-put /tmp/root-test-file trash-put: cannot trash non existent '/tmp/root-test-file' ``` Expected behavior: ``` $ rm protected-file.txt trash-put: cannot trash not accessible 'protected-file.txt' ``` Related code in `trashcli/put/describer.py` lines 40-41: ```python elif not self.fs.exists(path): return 'non existent' ```
0 条评论