refactor: use a map instead of a slice

Packages are unique anyways so it makes sense to use a map to avoid having
duplicates.

For compatibility reasons custom json (un)marshallers hide this change from the
end user
This commit is contained in:
sh0rez 2019-10-16 17:36:25 +02:00
parent 4b6e2d89e9
commit 6e3e7b2fdd
No known key found for this signature in database
GPG key ID: 87C71DF9F8181FF1
4 changed files with 52 additions and 17 deletions

View file

@ -34,15 +34,15 @@ func installCommand(dir, jsonnetHome string, uris []string) int {
}
kingpin.FatalIfError(
os.MkdirAll(filepath.Join(dir, "vendor", ".tmp"), os.ModePerm),
"creating vendor/ folder")
os.MkdirAll(filepath.Join(dir, jsonnetHome, ".tmp"), os.ModePerm),
"creating vendor folder")
jsonnetFile, err := jsonnetfile.Load(filepath.Join(dir, jsonnetfile.File))
kingpin.FatalIfError(err, "failed to load jsonnetfile")
for _, u := range uris {
d := parseDependency(dir, u)
jsonnetFile.Dependencies = append(jsonnetFile.Dependencies, *d)
jsonnetFile.Dependencies[d.Name] = *d
}
lockFile, err := jsonnetfile.Load(filepath.Join(dir, jsonnetfile.LockFile))
@ -50,12 +50,7 @@ func installCommand(dir, jsonnetHome string, uris []string) int {
kingpin.FatalIfError(err, "failed to load lockfile")
}
locks := make(map[string]spec.Dependency)
for _, d := range lockFile.Dependencies {
locks[d.Name] = d
}
locked, err := pkg.Ensure(jsonnetFile, jsonnetHome, locks)
locked, err := pkg.Ensure(jsonnetFile, jsonnetHome, lockFile.Dependencies)
kingpin.FatalIfError(err, "failed to install packages")
kingpin.FatalIfError(