Unverified Commit 025a3190 authored by Oren Shomron's avatar Oren Shomron Committed by GitHub
Browse files

Merge pull request #833 from shomron/issue-728

Allow reuse of installed packages in other scopes
parents dd57ff2b 4c7dd00d
......@@ -64,6 +64,28 @@ func CacheDependency(a app.App, checker InstalledChecker, d pkg.Descriptor, cust
return nil, err
}
libSpec, err := r.ResolveLibrarySpec(d.Name, d.Version)
if err != nil {
return nil, errors.Wrapf(err, "resolving package metadata: %v", d)
}
// Check whether this library version is already installed
var qualified = d
qualified.Version = libSpec.Version
ok, err := checker.IsInstalled(qualified)
if err != nil {
return nil, errors.Wrapf(err, "checking package installed status: %v", qualified)
}
if ok && !force {
// We will reuse the currently installed package files
return &app.LibraryConfig{
Registry: d.Registry,
Name: d.Name,
Version: libSpec.Version,
}, nil
}
// Get all directories and files first, then write to disk. This
// protects us from failing with a half-cached dependency because of
// a network failure.
......@@ -87,18 +109,6 @@ func CacheDependency(a app.App, checker InstalledChecker, d pkg.Descriptor, cust
// Make triple-sure the library references the correct registry, as it is known in this app.
libRef.Registry = d.Registry
// Check whether this library version is already installed
var qualified = d
qualified.Version = libRef.Version
ok, err := checker.IsInstalled(qualified)
if err != nil {
return nil, errors.Wrapf(err, "checking package installed status")
}
if ok && !force {
return nil, errors.Errorf("package '%s/%s@%s' already exists.",
libRef.Registry, libRef.Name, libRef.Version)
}
// Add library to app specification, but wait to write it out until
// the end, in case one of the network calls fails.
log.Infof("Retrieved %d files", len(files))
......
......@@ -321,6 +321,9 @@ func (gh *GitHub) ResolveLibrarySpec(partName, libRefSpec string) (*parts.Spec,
return nil, err
}
// For GitHub repositories, the SHA is the correct version, not what is written in the spec file.
parts.Version = resolvedSHA
return parts, nil
}
......
......@@ -377,6 +377,7 @@ func TestGithub_ResolveLibrarySpec(t *testing.T) {
APIVersion: "0.0.1",
Kind: "ksonnet.io/parts",
Name: "apache",
Version: "54321",
Description: "part description",
Author: "author",
Contributors: parts.ContributorSpecs{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment