Skip to content

bug fix: FillNarInfoCache for versioned packages when adding package #1437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions internal/impl/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,28 @@ func (d *Devbox) Add(ctx context.Context, platforms, excludePlatforms []string,
// to know the exact name to mark as allowed insecure later on.
addedPackageNames := []string{}
existingPackageNames := d.PackageNames()
newPackages := []*devpkg.Package{}
for _, pkg := range pkgs {
// If exact versioned package is already in the config, skip.
// If exact versioned package is already in the config, we can skip the
// next loop that only deals with newPackages.
if slices.Contains(existingPackageNames, pkg.Versioned()) {
// But we still need to add to addedPackageNames. See its comment.
addedPackageNames = append(addedPackageNames, pkg.Versioned())
continue
} else {
newPackages = append(newPackages, pkg)
}
}

// Fill in the narinfo cache for versioned newPackages as well
versionedPackages := map[string]*devpkg.Package{}
for _, pkg := range newPackages {
versionedPackages[pkg.Versioned()] = devpkg.PackageFromString(pkg.Versioned(), d.lockfile)
}
if err := devpkg.FillNarInfoCache(ctx, lo.Values(versionedPackages)...); err != nil {
return err
}

for _, pkg := range newPackages {

// On the other hand, if there's a package with same canonical name, replace
// it. Ignore error (which is either missing or more than one). We search by
Expand All @@ -73,7 +89,7 @@ func (d *Devbox) Add(ctx context.Context, platforms, excludePlatforms []string,

// validate that the versioned package exists in the search endpoint.
// if not, fallback to legacy vanilla nix.
versionedPkg := devpkg.PackageFromString(pkg.Versioned(), d.lockfile)
versionedPkg := versionedPackages[pkg.Versioned()]

packageNameForConfig := pkg.Raw
ok, err := versionedPkg.ValidateExists()
Expand Down