Skip to content

#735 Prevent modification of the user root folder.#736

Open
adiroiban wants to merge 1 commit into
masterfrom
735-prevent-virtual-root-delete
Open

#735 Prevent modification of the user root folder.#736
adiroiban wants to merge 1 commit into
masterfrom
735-prevent-virtual-root-delete

Conversation

@adiroiban

Copy link
Copy Markdown
Member

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

  • Add automated tests

How to try and test the changes

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adiroiban adiroiban changed the title Initial implementation. #735 Prevent modification of the user root folder. Jul 22, 2026
@greptile-apps

greptile-apps Bot commented Jul 25, 2026

Copy link
Copy Markdown
Prompt To Fix All With AI
Fix 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

Comment on lines 222 to 224
path = self.getRealPathFromSegments(segments, include_virtual=False)
if path == '/':
raise CompatError(1009, 'Deleting Unix root folder is not allowed.')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

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.

Comment on lines +390 to +396
def isRoot(self, segments):
"""
See `ILocalFilesystem`.
"""
path = self.getRealPathFromSegments(segments, include_virtual=False)
root = self.getRealPathFromSegments([], include_virtual=False)
return root.lower() == path.lower()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't delete the root segments

1 participant