Skip to content

Commit

Permalink
Copy symlink if origin of the link doesn't exist
Browse files Browse the repository at this point in the history
Fix #111
  • Loading branch information
otiai10 committed Sep 2, 2023
1 parent f0f65b5 commit 723a56e
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 @@ -254,14 +254,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 723a56e

Please sign in to comment.