Skip to content

Commit 97efeac

Browse files
committed
refactor for clarity
1 parent cdacb62 commit 97efeac

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

internal/devpkg/package.go

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -492,33 +492,33 @@ func (p *Package) HashFromNixPkgsURL() string {
492492
const BinaryCache = "https://cache.nixos.org"
493493

494494
func (p *Package) isEligibleForBinaryCache() (bool, error) {
495-
if !featureflag.RemoveNixpkgs.Enabled() {
496-
return false, nil
495+
sysInfo, err := p.sysInfoIfExists()
496+
if err != nil {
497+
return false, err
497498
}
499+
return sysInfo != nil, nil
500+
}
498501

499-
if !p.isVersioned() {
500-
return false, nil
502+
// sysInfoIfExists returns the system info for the user's system. If the sysInfo
503+
// is missing, then nil is returned
504+
func (p *Package) sysInfoIfExists() (*lock.SystemInfo, error) {
505+
if !featureflag.RemoveNixpkgs.Enabled() {
506+
return nil, nil
501507
}
502508

503-
sysInfo, err := p.sysInfoIfExists()
504-
if err != nil {
505-
return false, err
506-
} else if sysInfo == nil {
507-
return false, nil
509+
if !p.isVersioned() {
510+
return nil, nil
508511
}
509512

510513
version, err := nix.Version()
511514
if err != nil {
512-
return false, err
515+
return nil, err
513516
}
514517

515518
// enable for nix >= 2.17
516-
return vercheck.SemverCompare(version, "2.17.0") >= 0, nil
517-
}
518-
519-
// sysInfoIfExists returns the system info for the user's system. If the sysInfo
520-
// is missing, then nil is returned
521-
func (p *Package) sysInfoIfExists() (*lock.SystemInfo, error) {
519+
if vercheck.SemverCompare(version, "2.17.0") < 0 {
520+
return nil, err
521+
}
522522

523523
entry, err := p.lockfile.Resolve(p.Raw)
524524
if err != nil {
@@ -540,7 +540,7 @@ func (p *Package) sysInfoIfExists() (*lock.SystemInfo, error) {
540540
}
541541

542542
// IsInBinaryCache returns true if the package is in the binary cache.
543-
// Callers should call FillNarInfoCache before calling this function.
543+
// ALERT: Callers must call FillNarInfoCache before calling this function.
544544
func (p *Package) IsInBinaryCache() (bool, error) {
545545

546546
if eligible, err := p.isEligibleForBinaryCache(); err != nil {
@@ -684,19 +684,16 @@ func (p *storePathParts) Equal(other *storePathParts) bool {
684684
// package in the list, and caches the result.
685685
// Callers of IsInBinaryCache must call this function first.
686686
func FillNarInfoCache(ctx context.Context, packages ...*Package) error {
687-
g, ctx := errgroup.WithContext(ctx)
688-
687+
group, _ := errgroup.WithContext(ctx)
689688
for _, p := range packages {
690689
// If the package's NarInfo status is already known, skip it
691690
if _, ok := isNarInfoInCache[p.Raw]; ok {
692691
continue
693692
}
694-
g.Go(func() error {
695-
return p.fillNarInfoCache()
693+
pkg := p
694+
group.Go(func() error {
695+
return pkg.fillNarInfoCache()
696696
})
697697
}
698-
if err := g.Wait(); err != nil {
699-
return err
700-
}
701-
return nil
698+
return group.Wait()
702699
}

internal/impl/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (d *Devbox) Update(ctx context.Context, pkgs ...string) error {
4949
}
5050
}
5151

52-
if devpkg.FillNarInfoCache(ctx, pendingPackagesToUpdate...); err != nil {
52+
if err := devpkg.FillNarInfoCache(ctx, pendingPackagesToUpdate...); err != nil {
5353
return err
5454
}
5555

0 commit comments

Comments
 (0)