Skip to content

fix: handle ordinary directories when copying with -P - #1269

Open
ryanchou1994 wants to merge 1 commit into
shelljs:mainfrom
ryanchou1994:fix/cp-preserve-symlink-directories
Open

fix: handle ordinary directories when copying with -P#1269
ryanchou1994 wants to merge 1 commit into
shelljs:mainfrom
ryanchou1994:fix/cp-preserve-symlink-directories

Conversation

@ryanchou1994

Copy link
Copy Markdown

With -P, cp currently skips directory handling even when the source is an ordinary directory. Both cp -P source dest and cp -RP source dest then try to read that directory as a file and throw EISDIR.

Use lstat when preserving symlinks so ordinary directories still reach the existing directory handling: omit them without -R, or copy them recursively with -R. Actual symlinks remain preserved, and -L keeps its existing precedence.

Adds regressions for nonrecursive directory omission, recursive directory copying, and preserving a symlink inside a copied directory. All three fail on the original code.

Validation: npm test passes on macOS and Linux (627 passed, 6 skipped, including the posttest ESLint check); npm run check-node-support passes on Linux.

Fixes #937.

Copilot AI lite review requested due to automatic review settings September 12, 2026 08:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

CP on a folder fails when not following symlinks

2 participants