Skip to content

fix: refuse root as a source in cp and mv - #33

Merged
dsherret merged 1 commit into
mainfrom
cp-mv-root-source
Jul 14, 2026
Merged

fix: refuse root as a source in cp and mv#33
dsherret merged 1 commit into
mainfrom
cp-mv-root-source

Conversation

@dsherret

Copy link
Copy Markdown
Owner

Ports the follow-up commits on denoland/deno_task_shell#185 (the earlier commits there were already ported in #30 and #31).

  • cp -r / dest and mv / dest now error with the source has no final path component. Previously path.basename("/") returned an empty string, so calculateDestinationPath silently returned the destination itself — for cp that meant recursively copying the root over the destination path.
  • The mv ./.. guard now runs before building operations, matching upstream (so it fires before the "target is not a directory" check).
  • The raciness comment in doCopyOperation moved below the same-path guard since a string comparison isn't racy.

Ports the follow-up commits on denoland/deno_task_shell#185. A source
whose final path component is empty (ex. `/`) has no name to place
inside the destination, so cp and mv now error instead of silently
using the destination path itself. Also moves the raciness comment
below the same-path guard since a string comparison isn't racy.
@dsherret
dsherret merged commit 9d3378e into main Jul 14, 2026
4 checks passed
@dsherret
dsherret deleted the cp-mv-root-source branch July 14, 2026 16:15
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.

1 participant