Skip to content

Commit 230b4c4

Browse files
committed
When deploying via link, deploy symlinks directly instead of resolving them first.
1 parent f0c7784 commit 230b4c4

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

internal/smartlink/smartlink.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func LinkContents(src, dest string, visited map[string]bool) error {
2929
return errs.Wrap(err, "Reading dir %s failed", src)
3030
}
3131
for _, entry := range entries {
32-
if err := Link(filepath.Join(src, entry.Name()), filepath.Join(dest, entry.Name()), visited); err != nil {
32+
if err := Link(filepath.Join(src, entry.Name()), filepath.Join(dest, entry.Name())); err != nil {
3333
return errs.Wrap(err, "Link failed")
3434
}
3535
}
@@ -39,27 +39,21 @@ func LinkContents(src, dest string, visited map[string]bool) error {
3939

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.
42-
func Link(src, dest string, visited map[string]bool) error {
43-
srcWasSymlink := isSymlink(src)
44-
42+
func Link(src, dest string) error {
4543
var err error
4644
src, dest, err = resolvePaths(src, dest)
4745
if err != nil {
4846
return errs.Wrap(err, "Could not resolve src and dest paths")
4947
}
5048

51-
if visited == nil {
52-
visited = make(map[string]bool)
53-
}
54-
if _, exists := visited[src]; exists && srcWasSymlink {
55-
// We've encountered a recursive link. This is most often the case when the resolved src has
56-
// already been visited. In that case, just link the dest to the src (which may be a directory;
57-
// this is fine).
58-
return linkFile(src, dest)
59-
}
60-
visited[src] = true
61-
6249
if fileutils.IsDir(src) {
50+
if isSymlink(src) {
51+
// Links to directories are okay on Linux and macOS, but will fail on Windows.
52+
// If we ever get here on Windows, the artifact being deployed is bad and there's nothing we
53+
// can do about it except receive the report from Rollbar and report it internally.
54+
return linkFile(src, dest)
55+
}
56+
6357
if err := fileutils.Mkdir(dest); err != nil {
6458
return errs.Wrap(err, "could not create directory %s", dest)
6559
}
@@ -68,7 +62,7 @@ func Link(src, dest string, visited map[string]bool) error {
6862
return errs.Wrap(err, "could not read directory %s", src)
6963
}
7064
for _, entry := range entries {
71-
if err := Link(filepath.Join(src, entry.Name()), filepath.Join(dest, entry.Name()), visited); err != nil {
65+
if err := Link(filepath.Join(src, entry.Name()), filepath.Join(dest, entry.Name())); err != nil {
7266
return errs.Wrap(err, "sub link failed")
7367
}
7468
}
@@ -153,11 +147,11 @@ func isSymlink(src string) bool {
153147
// This is to ensure that we're always comparing apples to apples when doing string comparisons on paths.
154148
func resolvePaths(src, dest string) (string, string, error) {
155149
var err error
156-
src, err = fileutils.ResolveUniquePath(src)
150+
src, err = filepath.Abs(filepath.Clean(src))
157151
if err != nil {
158152
return "", "", errs.Wrap(err, "Could not resolve src path")
159153
}
160-
dest, err = fileutils.ResolveUniquePath(dest)
154+
dest, err = filepath.Abs(filepath.Clean(dest))
161155
if err != nil {
162156
return "", "", errs.Wrap(err, "Could not resolve dest path")
163157
}

0 commit comments

Comments
 (0)