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:
parent
3c98e86620
commit
139bdd07ea
@ -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 {
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user