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*
This commit is contained in:
Dominik Süß 2020-05-20 15:51:58 +02:00 committed by GitHub
parent 251792fbb2
commit 9e88f6d38d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View file

@ -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")
}