fix: disable sha256 for local packages

This commit is contained in:
sh0rez 2019-10-30 17:38:26 +01:00
parent 4de4096004
commit db1aae9b08
No known key found for this signature in database
GPG key ID: 87C71DF9F8181FF1
2 changed files with 17 additions and 3 deletions

View file

@ -50,7 +50,7 @@ func TestInstallCommand(t *testing.T) {
URIs: []string{"jsonnet/foobar"}, URIs: []string{"jsonnet/foobar"},
ExpectedCode: 0, ExpectedCode: 0,
ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}]}`), ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}]}`),
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "jsonnet/foobar"}}, "version": "", "sum": "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="}]}`), ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}]}`),
}, },
} }

View file

@ -155,7 +155,10 @@ func download(d spec.Dependency, vendorDir string) (*spec.Dependency, error) {
return nil, err return nil, err
} }
sum := hashDir(filepath.Join(vendorDir, d.Name)) var sum string
if d.Source.LocalSource == nil {
sum = hashDir(filepath.Join(vendorDir, d.Name))
}
return &spec.Dependency{ return &spec.Dependency{
Name: d.Name, Name: d.Name,
@ -166,8 +169,19 @@ func download(d spec.Dependency, vendorDir string) (*spec.Dependency, error) {
} }
// check returns whether the files present at the vendor/ folder match the // check returns whether the files present at the vendor/ folder match the
// sha256 sum of the package // sha256 sum of the package. local-directory dependencies are not checked as
// their purpose is to change during development where integrity checking would
// be a hindrance.
func check(d spec.Dependency, vendorDir string) bool { func check(d spec.Dependency, vendorDir string) bool {
// assume a local dependency is intact as long as it exists
if d.Source.LocalSource != nil {
x, err := jsonnetfile.Exists(filepath.Join(vendorDir, d.Name))
if err != nil {
return false
}
return x
}
if d.Sum == "" { if d.Sum == "" {
// no sum available, need to download // no sum available, need to download
return false return false