Skip to content

Commit

Permalink
Merge pull request #141 from otiai10/feature/symlink-exists-on-dest
Browse files Browse the repository at this point in the history
Copy symlink if origin of the link doesn't exist
  • Loading branch information
otiai10 committed Feb 8, 2024
2 parents 9ffcb0f + 723a56e commit 1b0f255
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,16 @@ func onsymlink(src, dest string, opt Options) error {
// lcopy is for a symlink,
// with just creating a new symlink by replicating src symlink.
func lcopy(src, dest string) error {
src, err := os.Readlink(src)
orig, err := os.Readlink(src)
// @See https://github.com/otiai10/copy/issues/111
// TODO: This might be controlled by Options in the future.
if err != nil {
if os.IsNotExist(err) {
return nil
if os.IsNotExist(err) { // Copy symlink even if not existing
return os.Symlink(src, dest)
}
return err
}
return os.Symlink(src, dest)
return os.Symlink(orig, dest)
}

// fclose ANYHOW closes file,
Expand Down

0 comments on commit 1b0f255

Please sign in to comment.