@@ -10,7 +10,7 @@ import (
10
10
)
11
11
12
12
// LinkContents will link the contents of src to desc
13
- func LinkContents (src , dest string , visited map [ string ] bool ) error {
13
+ func LinkContents (src , dest string ) error {
14
14
if ! fileutils .DirExists (src ) {
15
15
return errs .New ("src dir does not exist: %s" , src )
16
16
}
@@ -29,7 +29,7 @@ func LinkContents(src, dest string, visited map[string]bool) error {
29
29
return errs .Wrap (err , "Reading dir %s failed" , src )
30
30
}
31
31
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 {
33
33
return errs .Wrap (err , "Link failed" )
34
34
}
35
35
}
@@ -39,27 +39,21 @@ func LinkContents(src, dest string, visited map[string]bool) error {
39
39
40
40
// Link creates a link from src to target. MS decided to support Symlinks but only if you opt into developer mode (go figure),
41
41
// 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 {
45
43
var err error
46
44
src , dest , err = resolvePaths (src , dest )
47
45
if err != nil {
48
46
return errs .Wrap (err , "Could not resolve src and dest paths" )
49
47
}
50
48
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
-
62
49
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
+
63
57
if err := fileutils .Mkdir (dest ); err != nil {
64
58
return errs .Wrap (err , "could not create directory %s" , dest )
65
59
}
@@ -68,7 +62,7 @@ func Link(src, dest string, visited map[string]bool) error {
68
62
return errs .Wrap (err , "could not read directory %s" , src )
69
63
}
70
64
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 {
72
66
return errs .Wrap (err , "sub link failed" )
73
67
}
74
68
}
@@ -153,11 +147,11 @@ func isSymlink(src string) bool {
153
147
// This is to ensure that we're always comparing apples to apples when doing string comparisons on paths.
154
148
func resolvePaths (src , dest string ) (string , string , error ) {
155
149
var err error
156
- src , err = fileutils . ResolveUniquePath ( src )
150
+ src , err = filepath . Abs ( filepath . Clean ( src ) )
157
151
if err != nil {
158
152
return "" , "" , errs .Wrap (err , "Could not resolve src path" )
159
153
}
160
- dest , err = fileutils . ResolveUniquePath ( dest )
154
+ dest , err = filepath . Abs ( filepath . Clean ( dest ) )
161
155
if err != nil {
162
156
return "" , "" , errs .Wrap (err , "Could not resolve dest path" )
163
157
}
0 commit comments