1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-16 03:52:12 +02:00

fix: copy symlinks

closes #2496

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos A Becker 2021-10-12 15:03:46 -03:00
parent 3c98e86620
commit 139bdd07ea
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 28 additions and 0 deletions

View File

@ -35,6 +35,9 @@ func CopyWithMode(src, dst string, mode os.FileMode) error {
if info.IsDir() {
return os.MkdirAll(dst, info.Mode())
}
if info.Mode()&os.ModeSymlink != 0 {
return copySymlink(path, dst)
}
if mode != 0 {
return copyFile(path, dst, mode)
}
@ -42,6 +45,14 @@ func CopyWithMode(src, dst string, mode os.FileMode) error {
})
}
func copySymlink(src, dst string) error {
src, err := os.Readlink(src)
if err != nil {
return err
}
return os.Symlink(src, dst)
}
func copyFile(src, dst string, mode os.FileMode) error {
original, err := os.Open(src)
if err != nil {

View File

@ -17,6 +17,23 @@ func TestCopy(t *testing.T) {
requireEqualFiles(t, a, b)
}
func TestCopySymlink(t *testing.T) {
tmp := t.TempDir()
a := "testdata/somefile.txt"
b := tmp + "/somefile.txt"
c := tmp + "/somefile2.txt"
require.NoError(t, os.Symlink(a, b))
require.NoError(t, Copy(b, c))
fi, err := os.Lstat(c)
require.NoError(t, err)
require.True(t, fi.Mode()&os.ModeSymlink != 0)
l, err := os.Readlink(c)
require.NoError(t, err)
require.Equal(t, a, l)
}
func TestEqualFilesModeChanged(t *testing.T) {
tmp := t.TempDir()
a := "testdata/somefile.txt"