From 9e88f6d38d2c12ea86ea04ded932a106fa5df972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=BC=C3=9F?= Date: Wed, 20 May 2020 15:51:58 +0200 Subject: [PATCH] fix: windows enhancements (#110) * use filepath to check for known packages this fixes an issue using windows. without this patch, jb would delete the folder after installation since the path is not known * reduce temp directory length by hashing using this hash it is harder to reach the windows limit for filenames and directories * further reduce temp dir length * do not build binaries for windows/amd* --- Makefile | 1 + pkg/git.go | 6 +++++- pkg/packages.go | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2ccd60b..0aca0c5 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ cross: clean -ldflags=$(LDFLAGS) \ -arch="amd64 arm64 arm" -os="linux" \ -osarch="darwin/amd64" \ + -osarch="windows/amd64" \ ./cmd/$(BIN) static: diff --git a/pkg/git.go b/pkg/git.go index c11d399..2eb6de7 100644 --- a/pkg/git.go +++ b/pkg/git.go @@ -19,6 +19,8 @@ import ( "bytes" "compress/gzip" "context" + "crypto/sha256" + "encoding/hex" "fmt" "io" "io/ioutil" @@ -176,7 +178,9 @@ func remoteResolveRef(ctx context.Context, remote string, ref string) (string, e func (p *GitPackage) Install(ctx context.Context, name, dir, version string) (string, error) { destPath := path.Join(dir, name) - tmpDir, err := ioutil.TempDir(filepath.Join(dir, ".tmp"), fmt.Sprintf("jsonnetpkg-%s-%s", strings.Replace(name, "/", "-", -1), version)) + pkgh := sha256.Sum256([]byte(fmt.Sprintf("jsonnetpkg-%s-%s", strings.Replace(name, "/", "-", -1), version))) + // using 16 bytes should be a good middle ground between length and collision resistance + tmpDir, err := ioutil.TempDir(filepath.Join(dir, ".tmp"), hex.EncodeToString(pkgh[:16])) if err != nil { return "", errors.Wrap(err, "failed to create tmp dir") } diff --git a/pkg/packages.go b/pkg/packages.go index b957532..98828ae 100644 --- a/pkg/packages.go +++ b/pkg/packages.go @@ -200,6 +200,7 @@ func checkLegacyNameTaken(legacyName string, pkgName string) (bool, error) { } func known(deps map[string]deps.Dependency, p string) bool { + p = filepath.ToSlash(p) for _, d := range deps { k := d.Name() if strings.HasPrefix(p, k) || strings.HasPrefix(k, p) {