-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch version/0-46-0-RC1 to adopt changes from PR #3502
- Loading branch information
Showing
3 changed files
with
87 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build linux || darwin | ||
// +build linux darwin | ||
|
||
package runtime | ||
|
||
func supportsHardLinks(path string) bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package runtime | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/ActiveState/cli/internal/fileutils" | ||
"github.com/ActiveState/cli/internal/logging" | ||
"github.com/ActiveState/cli/internal/multilog" | ||
"github.com/ActiveState/cli/internal/smartlink" | ||
) | ||
|
||
const linkTarget = "__target__" | ||
const link = "__link__" | ||
|
||
func supportsHardLinks(path string) (supported bool) { | ||
defer func() { | ||
if !supported { | ||
logging.Debug("Enforcing deployment via copy, as hardlinks are not supported") | ||
} | ||
}() | ||
|
||
target := filepath.Join(path, linkTarget) | ||
err := fileutils.Touch(target) | ||
if err != nil { | ||
multilog.Error("Error touching target: %v", err) | ||
return false | ||
} | ||
defer func() { | ||
err := os.Remove(target) | ||
if err != nil { | ||
multilog.Error("Error removing target: %v", err) | ||
} | ||
}() | ||
|
||
lnk := filepath.Join(path, link) | ||
if fileutils.TargetExists(lnk) { | ||
err := os.Remove(lnk) | ||
if err != nil { | ||
multilog.Error("Error removing previous link: %v", err) | ||
return false | ||
} | ||
} | ||
|
||
logging.Debug("Attempting to link '%s' to '%s'", lnk, target) | ||
err = smartlink.Link(target, lnk) | ||
if err != nil { | ||
logging.Debug("Test link creation failed: %v", err) | ||
return false | ||
} | ||
err = os.Remove(lnk) | ||
if err != nil { | ||
multilog.Error("Error removing link: %v", err) | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters