Skip to content

Commit

Permalink
Merge pull request #145 from apprehensions/main
Browse files Browse the repository at this point in the history
Overwrite symlink
  • Loading branch information
otiai10 committed Mar 6, 2024
2 parents 1b0f255 + 6fbec09 commit 9e436a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestCopy(t *testing.T) {

When(t, "try to copy to an existing path", func(t *testing.T) {
err := Copy("test/data/case03", "test/data.copy/case03")
Expect(t, err).Not().ToBe(nil)
Expect(t, err).ToBe(nil)
})

When(t, "try to copy READ-not-allowed source", func(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ func lcopy(src, dest string) error {
}
return err
}

// @See https://github.com/otiai10/copy/issues/132
// TODO: Control by SymlinkExistsAction
if _, err := os.Lstat(dest); err == nil {
if err := os.Remove(dest); err != nil {
return err
}
}

return os.Symlink(orig, dest)
}

Expand Down

0 comments on commit 9e436a9

Please sign in to comment.