-
Notifications
You must be signed in to change notification settings - Fork 1k
internal/fs: don't clone symlinks on windows #781
internal/fs: don't clone symlinks on windows #781
Conversation
1ab4923
to
34d3314
Compare
internal/fs/fs_test.go
Outdated
if err = os.Symlink(srcPath, symlinkPath); err != nil { | ||
t.Fatalf("could not create symlink: %v", err) | ||
} | ||
if runtime.GOOS == "window" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"windows"
Transforming symlinks into their referent directory and copying them is a pretty drastic change. For some of the uses of this func, it's likely fine. Others might present complications, though. Could we please enumerate each of the places this logic will be triggered (so, calls from outside the |
Just to clarify, we don't transform the symlink into anything.
This renders the symlink useless on Windows. So if a dependency relies on symlinks functioning, something will most likely break and that is the part that really worries me. |
For the record,
|
internal/fs/fs.go
Outdated
// Creating symlinks on Windows require an additional permission regular | ||
// users aren't granted usually. So we skip cloning the symlink nd copy the | ||
// file content as a fall back instead. | ||
if sym && runtime.GOOS != "windows" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we were to try it even on windows, and if we encounter the particular error, then fall back to cloning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should work.
I'm only worried about not having a clear path of execution. The more conditionals paths we have the harder it's to reproduce output or debug strange behavior because the input list grows exponentially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course - more if branches, more cyclomatic complexity. but the side effects here worry me enough that i think it's merited 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
db67dbf
to
80ad660
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, the review looked good, but apparently we have test failures 😢
d4803f7
to
2ea710d
Compare
Fixed tests. |
This change updates TestCopyFileSymlink tests and renames copySymlink to cloneSymlink to clarify the intention. Fixes golang#773 Signed-off-by: Ibrahim AshShohail <ibra.sho@gmail.com>
545881f
to
90c2a36
Compare
internal/fs/fs.go
Outdated
} else if sym { | ||
return cloneSymlink(src, dst) | ||
if err := cloneSymlink(src, dst); err != nil { | ||
if runtime.GOOS == "windows" && strings.HasSuffix(err.Error(), "A required privilege is not held by the client.") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't i18n-friendly. not a blocker, necessarily, but is there any way we could sniff the system actual error type here? obviously that means syscall, so this'd have to be a in a windows-tagged file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Didn't think of that. Updating now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I solved it in an OS-independent way. Let me know if a windows-tagged file is still needed.
Signed-off-by: Ibrahim AshShohail <ibra.sho@gmail.com>
fb26cc3
to
ced76d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, i think we're good here. thanks for your patience, as always! 🎉
What does this do / why do we need it?
fs.copyFile
callsfs.copySymlink
on Windows which fails if the user doesn't have the required permission. This is a very common case since symlinks are used heavily on Windows.This change renames
fs.copySymlink
tofs.cloneSymlink
to clarify the intent and skips calling it when on Windows to fall back to copying the file content instead.What should your reviewer look out for in this PR?
Generic review.
Which issue(s) does this PR fix?
Fixes #773