-
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.
Test for hardlink support on Windows before doing it.
- Loading branch information
1 parent
948ebeb
commit 255d3f9
Showing
3 changed files
with
71 additions
and
7 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
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,50 @@ | ||
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) { | ||
logging.Debug("Determining if hard links are supported for drive associated with '%s'", path) | ||
defer func() { | ||
log := "Yes they are" | ||
if !supported { | ||
log = "No they are not" | ||
} | ||
logging.Debug(log) | ||
}() | ||
|
||
target := filepath.Join(path, linkTarget) | ||
if !fileutils.TargetExists(target) { | ||
err := fileutils.Touch(target) | ||
if err != nil { | ||
multilog.Error("Error touching target: %v", err) | ||
return false | ||
} | ||
} | ||
|
||
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 err == nil | ||
} |