Skip to content

Commit d1a7e18

Browse files
committed
Minimize changes from previous commit.
1 parent b75482b commit d1a7e18

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

internal/smartlink/smartlink.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,23 @@ func LinkContents(src, dest string) error {
4040
// Link creates a link from src to target. MS decided to support Symlinks but only if you opt into developer mode (go figure),
4141
// which we cannot reasonably force on our users. So on Windows we will instead create dirs and hardlinks.
4242
func Link(src, dest string) error {
43+
originalSrc := src
44+
4345
var err error
4446
src, dest, err = resolvePaths(src, dest)
4547
if err != nil {
4648
return errs.Wrap(err, "Could not resolve src and dest paths")
4749
}
4850

4951
if fileutils.IsDir(src) {
50-
if isSymlink(src) {
52+
if fileutils.IsSymlink(originalSrc) {
53+
// If the original src is a symlink, the resolved src is no longer a symlink and could point
54+
// to a parent directory, resulting in a recursive directory structure.
55+
// Avoid any potential problems by simply linking the original link to the target.
5156
// Links to directories are okay on Linux and macOS, but will fail on Windows.
5257
// If we ever get here on Windows, the artifact being deployed is bad and there's nothing we
5358
// can do about it except receive the report from Rollbar and report it internally.
54-
return linkFile(src, dest)
59+
return linkFile(originalSrc, dest)
5560
}
5661

5762
if err := fileutils.Mkdir(dest); err != nil {
@@ -138,20 +143,15 @@ func UnlinkContents(src, dest string) error {
138143
return nil
139144
}
140145

141-
func isSymlink(src string) bool {
142-
target, err := fileutils.SymlinkTarget(src)
143-
return err == nil && src != target
144-
}
145-
146146
// resolvePaths will resolve src and dest to absolute paths and return them.
147147
// This is to ensure that we're always comparing apples to apples when doing string comparisons on paths.
148148
func resolvePaths(src, dest string) (string, string, error) {
149149
var err error
150-
src, err = filepath.Abs(filepath.Clean(src))
150+
src, err = fileutils.ResolveUniquePath(src)
151151
if err != nil {
152152
return "", "", errs.Wrap(err, "Could not resolve src path")
153153
}
154-
dest, err = filepath.Abs(filepath.Clean(dest))
154+
dest, err = fileutils.ResolveUniquePath(dest)
155155
if err != nil {
156156
return "", "", errs.Wrap(err, "Could not resolve dest path")
157157
}

0 commit comments

Comments
 (0)