Skip to content

Commit

Permalink
manifestgen: use XDG_CACHE_HOME for the depsolve cache
Browse files Browse the repository at this point in the history
This commit changes the depsolve cache to a persistent location
to speed up the resolving.

Thanks to Achilleas for the suggestion.
  • Loading branch information
mvo5 authored and supakeen committed Jan 24, 2025
1 parent e9bddf0 commit cf2b0d5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/manifestgen/manifestgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"slices"
"strings"

Expand All @@ -24,6 +25,8 @@ import (
const (
defaultDepsolverSBOMType = sbom.StandardTypeSpdx
defaultSBOMExt = "spdx.json"

defaultDepsolveCacheDir = "osbuild-depsolve-dnf"
)

// Options contains the optional settings for the manifest generation.
Expand Down Expand Up @@ -178,17 +181,28 @@ func (mg *Generator) Generate(bp *blueprint.Blueprint, dist distro.Distro, imgTy
return nil
}

func xdgCacheHome() (string, error) {
xdgCacheHome := os.Getenv("XDG_CACHE_HOME")
if xdgCacheHome != "" {
return xdgCacheHome, nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, ".cache"), nil
}

// DefaultDepsolver provides a default implementation for depsolving.
// It should rarely be necessary to use it directly and will be used
// by default by manifestgen (unless overriden)
func DefaultDepsolver(cacheDir string, packageSets map[string][]rpmmd.PackageSet, d distro.Distro, arch string) (map[string]dnfjson.DepsolveResult, error) {
if cacheDir == "" {
var err error
cacheDir, err = os.MkdirTemp("", "manifestgen")
xdgCacheHomeDir, err := xdgCacheHome()
if err != nil {
return nil, fmt.Errorf("cannot create temporary directory: %w", err)
return nil, err
}
defer os.RemoveAll(cacheDir)
cacheDir = filepath.Join(xdgCacheHomeDir, defaultDepsolveCacheDir)
}

solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch, d.Name(), cacheDir)
Expand Down

0 comments on commit cf2b0d5

Please sign in to comment.