diff --git a/all_test.go b/all_test.go index 0f03637..a2bcd0c 100644 --- a/all_test.go +++ b/all_test.go @@ -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) { diff --git a/copy.go b/copy.go index 4a6c0e3..39a0b01 100644 --- a/copy.go +++ b/copy.go @@ -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) }