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 relative symlinks deep copying #151

Merged
merged 1 commit into from
Jun 15, 2024
Merged

Fix relative symlinks deep copying #151

merged 1 commit into from
Jun 15, 2024

Conversation

psergee
Copy link
Contributor

@psergee psergee commented Jun 1, 2024

All relative paths of symbolic links should be resolved from the directory where the link is located. The current working directory does not affect the resolution of the path. A symbolic link can be absolute or relative, and may or may not have a leading dot. Directory content example:

file
symlink -> file

Copying of the directory with such content does not work currently. When copying symlink, Copy returns an error because the file does not exist in the current working directory. In the existing tests, there is a symbolic link named "symlink" that points to a file named "README.md". However, when resolving the path of the file, the file is located in the repository's root directory, not the test case directory, and copying of these dirs work fine.

The solution is to check whether the resolved path is absolute or not. If it is not, append it to the file's directory path.

@otiai10 otiai10 self-assigned this Jun 4, 2024
All relative paths of symbolic links should be resolved from the
directory where the link is located. The current working directory
does not affect the resolution of the path. A symbolic link can
be absolute or relative, and may or may not have a leading dot.
Directory content example:
file
symlink -> file
Copying of the directory with such content does not work currently.
When copying `symlink`, `Copy` returns an error because the `file`
does not exist in the current working directory. In the existing
tests, there is a symbolic link named "symlink" that points to a
file named "README.md". However, when resolving the path of the
file, the file is located in the repository's root directory,
not the test case directory, and copying of these dirs work fine.

The solution is to check whether the resolved path is absolute
or not. If it is not, append it to the file's directory path.
@@ -293,7 +292,7 @@ func onsymlink(src, dest string, opt Options) error {
if err != nil {
return err
}
if strings.HasPrefix(orig, ".") {
if !filepath.IsAbs(orig) {
Copy link
Owner

Choose a reason for hiding this comment

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

You are right. Thank you!

@otiai10 otiai10 merged commit 570479c into otiai10:main Jun 15, 2024
21 checks passed
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.

None yet

2 participants