@@ -24,17 +24,6 @@ func LinkContents(src, dest string, visited map[string]bool) error {
2424 return errs .Wrap (err , "Could not resolve src and dest paths" )
2525 }
2626
27- if visited == nil {
28- visited = make (map [string ]bool )
29- }
30- if _ , exists := visited [src ]; exists {
31- // We've encountered a recursive link. This is most often the case when the resolved src has
32- // already been visited. In that case, just link the dest to the src (which may be a directory;
33- // this is fine).
34- return linkFile (src , dest )
35- }
36- visited [src ] = true
37-
3827 entries , err := os .ReadDir (src )
3928 if err != nil {
4029 return errs .Wrap (err , "Reading dir %s failed" , src )
@@ -51,6 +40,8 @@ func LinkContents(src, dest string, visited map[string]bool) error {
5140// Link creates a link from src to target. MS decided to support Symlinks but only if you opt into developer mode (go figure),
5241// which we cannot reasonably force on our users. So on Windows we will instead create dirs and hardlinks.
5342func Link (src , dest string , visited map [string ]bool ) error {
43+ srcWasSymlink := isSymlink (src )
44+
5445 var err error
5546 src , dest , err = resolvePaths (src , dest )
5647 if err != nil {
@@ -60,7 +51,7 @@ func Link(src, dest string, visited map[string]bool) error {
6051 if visited == nil {
6152 visited = make (map [string ]bool )
6253 }
63- if _ , exists := visited [src ]; exists {
54+ if _ , exists := visited [src ]; exists && srcWasSymlink {
6455 // We've encountered a recursive link. This is most often the case when the resolved src has
6556 // already been visited. In that case, just link the dest to the src (which may be a directory;
6657 // this is fine).
@@ -153,6 +144,11 @@ func UnlinkContents(src, dest string) error {
153144 return nil
154145}
155146
147+ func isSymlink (src string ) bool {
148+ target , err := fileutils .SymlinkTarget (src )
149+ return err == nil && src != target
150+ }
151+
156152// resolvePaths will resolve src and dest to absolute paths and return them.
157153// This is to ensure that we're always comparing apples to apples when doing string comparisons on paths.
158154func resolvePaths (src , dest string ) (string , string , error ) {
0 commit comments