Skip to content

fix(chgrp,chown): refuse "." spellings resolved onto the shell root (#1259) - #1266

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1259
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1259

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • chown -R --preserve-root X . (and ./, ././, or any operand resolving to the same directory) from a cwd that IS the shell root used to walk the shell tree: the failsafe only matched spellings naming the volume root.
  • GNU compares the operand's device+inode against /. We now resolve the operand to a full path and compare it against / resolved through the same operand layer — which names the shell root when one is configured (__RUBASH_SHELL_ROOT/NIU_ROOT/WINUXSH_ROOT/RUBASH_ROOT) and the current-drive root otherwise. That is the dev+ino parity target.
  • Refusals print it is dangerous to operate recursively on '<operand>' (same as '/') + use --no-preserve-root to override this failsafe, matching MSYS.
  • Applies to both chown and chgrp (twin get_preserve_root_match implementations), under -R --preserve-root only.

No new user-visible strings were introduced — the refusal reuses the existing literals — so no i18n catalog change is required.

Fixes #1259.

Test plan

  • winuxcmd-tests.exe --gtest_filter=chown.*:chgrp.* — 61/61 passed

Generated with Devin

…1259)

GNU's preserve-root failsafe compares the operand's device+inode against
"/", so chown -R --preserve-root X . with a cwd that IS the shell root is
refused like "/". The failsafe only matched spellings naming the volume
root, so ".", "./" and "././" walked the shell tree.

Compare the operand's resolved path against "/" resolved through the same
operand layer: it names the shell root when one is configured and the
current-drive root otherwise, which is the dev+ino parity target. The
refusal prints the "(same as '/')" suffix exactly like MSYS.

Fixes #1259.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

preserve-root 边角: 在 shell root 处仍走树(GNU dev+ino 会拒)——#1249 CR nits

1 participant