#735 Prevent modification of the user root folder.#736
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
src/chevah_compat/unix_filesystem.py:222-224
**Unreachable legacy root check**
The `if path == '/'` guard (line 224) is now dead code. `_rejectRoot` at the top of this method calls `isRoot`, which already raises `CompatError(1009, ...)` before execution reaches the old check. The two checks also emit different error messages, which could be confusing during debugging if the legacy block were ever reachable.
### Issue 2 of 2
src/chevah_compat/posix_filesystem.py:390-396
**Case-insensitive comparison applied to POSIX paths**
`isRoot` uses `.lower()` on both paths unconditionally. On case-sensitive POSIX filesystems (Linux ext4, etc.), a virtual root configured as `/Home/sftp_root` and a path `/home/sftp_root` would be considered equal, incorrectly blocking operations on the distinct lowercase path. Consider limiting the case-insensitive fold to Windows only, or using `os.path.normcase` which already applies `.lower()` on Windows and is a no-op on POSIX.
```suggestion
return os.path.normcase(root) == os.path.normcase(path)
```
Reviews (1): Last reviewed commit: "Initial implementation." | Re-trigger Greptile |
| path = self.getRealPathFromSegments(segments, include_virtual=False) | ||
| if path == '/': | ||
| raise CompatError(1009, 'Deleting Unix root folder is not allowed.') |
There was a problem hiding this comment.
The if path == '/' guard (line 224) is now dead code. _rejectRoot at the top of this method calls isRoot, which already raises CompatError(1009, ...) before execution reaches the old check. The two checks also emit different error messages, which could be confusing during debugging if the legacy block were ever reachable.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/chevah_compat/unix_filesystem.py
Line: 222-224
Comment:
**Unreachable legacy root check**
The `if path == '/'` guard (line 224) is now dead code. `_rejectRoot` at the top of this method calls `isRoot`, which already raises `CompatError(1009, ...)` before execution reaches the old check. The two checks also emit different error messages, which could be confusing during debugging if the legacy block were ever reachable.
How can I resolve this? If you propose a fix, please make it concise.| def isRoot(self, segments): | ||
| """ | ||
| See `ILocalFilesystem`. | ||
| """ | ||
| path = self.getRealPathFromSegments(segments, include_virtual=False) | ||
| root = self.getRealPathFromSegments([], include_virtual=False) | ||
| return root.lower() == path.lower() |
There was a problem hiding this comment.
Case-insensitive comparison applied to POSIX paths
isRoot uses .lower() on both paths unconditionally. On case-sensitive POSIX filesystems (Linux ext4, etc.), a virtual root configured as /Home/sftp_root and a path /home/sftp_root would be considered equal, incorrectly blocking operations on the distinct lowercase path. Consider limiting the case-insensitive fold to Windows only, or using os.path.normcase which already applies .lower() on Windows and is a no-op on POSIX.
| def isRoot(self, segments): | |
| """ | |
| See `ILocalFilesystem`. | |
| """ | |
| path = self.getRealPathFromSegments(segments, include_virtual=False) | |
| root = self.getRealPathFromSegments([], include_virtual=False) | |
| return root.lower() == path.lower() | |
| return os.path.normcase(root) == os.path.normcase(path) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/chevah_compat/posix_filesystem.py
Line: 390-396
Comment:
**Case-insensitive comparison applied to POSIX paths**
`isRoot` uses `.lower()` on both paths unconditionally. On case-sensitive POSIX filesystems (Linux ext4, etc.), a virtual root configured as `/Home/sftp_root` and a path `/home/sftp_root` would be considered equal, incorrectly blocking operations on the distinct lowercase path. Consider limiting the case-insensitive fold to Windows only, or using `os.path.normcase` which already applies `.lower()` on Windows and is a no-op on POSIX.
```suggestion
return os.path.normcase(root) == os.path.normcase(path)
```
How can I resolve this? If you propose a fix, please make it concise.
Scope
Fixes #735
Update the filesystem handler to prevent operation on the root folder.
Changes
Add a helper to raise an exception.
Guard all operations that can mutate the root.
Todo
How to try and test the changes