feat: add preserve root protection and namespace#26
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds root-path protection to rm-safely (including in --rm bypass mode) and namespaces hook helper functions to reduce shell symbol collisions, along with new tests and a Dockerized cross-distro test runner.
Changes:
- Namespaced hook helper functions with
_rm_safely_*and added root (/) detection/protection logic. - Added a dedicated preserve-root regression test script.
- Introduced Dockerfiles + docker-compose to run E2E + preserve-root tests on Ubuntu/Alpine/FreeBSD.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
rm-safely |
Namespaces internal hook helpers and adds “preserve root” protection logic. |
tests/test_preserve_root.sh |
Adds a test suite asserting / removal is blocked in both trash and --rm modes. |
docker/docker-compose.yml |
Adds multi-distro test orchestration (Ubuntu/Alpine/FreeBSD). |
docker/Dockerfile.ubuntu |
Builds an Ubuntu test image and installs the hook for test execution. |
docker/Dockerfile.alpine |
Builds an Alpine test image and installs the hook for test execution. |
docker/Dockerfile.freebsd |
Builds a FreeBSD test image and installs the hook for test execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+134
to
+139
| local p="$1" | ||
| [[ "$p" != -* ]] || return 1 | ||
| [[ "$p" = /* ]] && p="$p" || p="$(pwd)/$p" | ||
| p="$(cd "$p" 2>/dev/null && pwd || echo "$p")" | ||
| p="${p%/}" | ||
| [ -z "$p" ] || [ "$p" = "/" ] |
Comment on lines
+7
to
+12
| bash -c " | ||
| echo '=== Ubuntu $(cat /etc/os-release | grep VERSION_ID | cut -d= -f2) ===' && | ||
| echo '--- E2E Tests ---' && | ||
| bash tests/test_e2e.sh && | ||
| echo '--- Preserve Root Tests ---' && | ||
| bash tests/test_preserve_root.sh |
Comment on lines
+33
to
+38
| sh -c " | ||
| echo '=== FreeBSD ===' && | ||
| echo '--- E2E Tests ---' && | ||
| sh tests/test_e2e.sh && | ||
| echo '--- Preserve Root Tests ---' && | ||
| sh tests/test_preserve_root.sh |
Comment on lines
+7
to
+9
| RUN sh rm-safely install | ||
|
|
||
| CMD ["sh", "tests/test_e2e.sh"] |
Refuse to remove '/' by default, matching GNU rm behavior. Refactor internal helper functions to prefix with _rm_safely_ to avoid shell namespace collisions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.