Skip to content

feat: add preserve root protection and namespace#26

Merged
zdk merged 1 commit intomainfrom
feat/preserve-root
Mar 17, 2026
Merged

feat: add preserve root protection and namespace#26
zdk merged 1 commit intomainfrom
feat/preserve-root

Conversation

@zdk
Copy link
Copy Markdown
Owner

@zdk zdk commented Mar 17, 2026

No description provided.

@zdk zdk self-assigned this Mar 17, 2026
@zdk zdk requested a review from Copilot March 17, 2026 07:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.
@zdk zdk force-pushed the feat/preserve-root branch from bf284a6 to b3a0f70 Compare March 17, 2026 07:24
@zdk zdk merged commit ec548af into main Mar 17, 2026
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.

2 participants