otiai10 / copy

Go copy directory recursively
https://pkg.go.dev/github.com/otiai10/copy
MIT License
722 stars 115 forks source link

Fix relative symlinks deep copying #151

Closed psergee closed 4 months ago

psergee commented 5 months ago

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.