-
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 818c474
Showing
3 changed files
with
88 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,5 @@ | ||
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,70 @@ | ||
package runtime | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
|
||
"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(target) { | ||
err := smartlink.LinkContents(target, lnk) | ||
if err != nil { | ||
multilog.Error("Error creating link: %v", err) | ||
return false | ||
} | ||
} | ||
|
||
infoTarget, err := os.Stat(target) | ||
if err != nil { | ||
multilog.Error("Error reading target: %v", err) | ||
return false | ||
} | ||
|
||
infoLink, err := os.Stat(lnk) | ||
if err != nil { | ||
multilog.Error("Error reading link: %v", err) | ||
return false | ||
} | ||
|
||
statTarget, ok := infoTarget.Sys().(*syscall.Stat_t) | ||
if !ok { | ||
multilog.Error("Error casting target info") | ||
return false | ||
} | ||
|
||
statLink, ok := infoLink.Sys().(*syscall.Stat_t) | ||
if !ok { | ||
multilog.Error("Error casting link info") | ||
return false | ||
} | ||
|
||
return statTarget.Dev == statLink.Dev && statTarget.Ino == statLink.Ino | ||
} |