Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fs): fix copying of symlink directories on Windows #6278

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fs/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async function copySymLink(
) {
await ensureValidCopy(src, dest, options);
const originSrcFilePath = await Deno.readLink(src);
Copy link
Contributor

Choose a reason for hiding this comment

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

Using Deno.realPath should return the absolute path of the symlink target. Additional explanation for suggestion in PR #6236:

Suggested change
const originSrcFilePath = await Deno.readLink(src);
const originSrcFilePath = await Deno.realPath(src);

Copy link
Member

Choose a reason for hiding this comment

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

I think changing this to realPath causes another problem. I think we should keep this work for relative symlinks.

const type = getFileInfoType(await Deno.lstat(src));
const type = getFileInfoType(await Deno.lstat(originSrcFilePath));
Copy link
Member

Choose a reason for hiding this comment

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

I think this only works when originSrcFilePath is an absolute path or relative path accidentally points to path accessible from cwd. originSrcFilePath could be relative path from link path to target, which could be inaccessible from cwd, and in that case this lstat call would fail.

I think this should Deno.stat(src) instead with fallback to 'file' type in case Deno.stat(src) throws NotFound. What do you think?

if (isWindows) {
await Deno.symlink(originSrcFilePath, dest, {
type: type === "dir" ? "dir" : "file",
Expand All @@ -161,7 +161,7 @@ function copySymlinkSync(
) {
ensureValidCopySync(src, dest, options);
const originSrcFilePath = Deno.readLinkSync(src);
Copy link
Contributor

Choose a reason for hiding this comment

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

Using Deno.realPathSync should return the absolute path of the symlink target. Additional explanation for suggestion in PR #6236:

Suggested change
const originSrcFilePath = Deno.readLinkSync(src);
const originSrcFilePath = Deno.realPathSync(src);

const type = getFileInfoType(Deno.lstatSync(src));
const type = getFileInfoType(Deno.lstatSync(originSrcFilePath));
if (isWindows) {
Deno.symlinkSync(originSrcFilePath, dest, {
type: type === "dir" ? "dir" : "file",
Expand Down
Loading