dnf-json: make cachedir mandatory

Without passing in a cachedir, dnf would create a random one for every
invocation. This meant that caches were never reused, nor cleaned up
properly.

Let systemd create a cache directory for us in /var/cache/ and use
that via the environment variable systemd sets for us.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-02-19 21:34:13 +01:00 committed by msehnout
parent 8b7b592bd2
commit 44c03cf61e
3 changed files with 8 additions and 5 deletions

View file

@ -7,6 +7,7 @@ Wants=osbuild-worker@1.service
[Service]
Type=simple
ExecStart=/usr/libexec/osbuild-composer/osbuild-composer
CacheDirectory=osbuild-composer
StateDirectory=osbuild-composer
WorkingDirectory=/usr/libexec/osbuild-composer/
User=_osbuild-composer

View file

@ -43,8 +43,7 @@ def create_base(repos, module_platform_id, persistdir, cachedir, clean=False):
base.conf.module_platform_id = module_platform_id
base.conf.config_file_path = "/dev/null"
base.conf.persistdir = persistdir
if cachedir:
base.conf.cachedir = cachedir
base.conf.cachedir = cachedir
if clean:
shutil.rmtree(base.conf.cachedir, ignore_errors=True)
@ -90,7 +89,7 @@ command = call["command"]
arguments = call["arguments"]
repos = arguments.get("repos", {})
clean = arguments.get("clean", False)
cachedir = arguments.get("cachedir", None)
cachedir = arguments["cachedir"]
module_platform_id = arguments["module_platform_id"]
with tempfile.TemporaryDirectory() as persistdir:

View file

@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"path"
"sort"
"time"
@ -216,8 +217,9 @@ func NewRPMMD() RPMMD {
func (*rpmmdImpl) FetchMetadata(repos []RepoConfig, modulePlatformID string) (PackageList, map[string]string, error) {
var arguments = struct {
Repos []RepoConfig `json:"repos"`
CacheDir string `json:"cachedir"`
ModulePlatformID string `json:"module_platform_id"`
}{repos, modulePlatformID}
}{repos, path.Join(os.Getenv("CACHE_DIRECTORY"), "rpmmd"), modulePlatformID}
var reply struct {
Checksums map[string]string `json:"checksums"`
Packages PackageList `json:"packages"`
@ -234,9 +236,10 @@ func (*rpmmdImpl) Depsolve(specs, excludeSpecs []string, repos []RepoConfig, mod
PackageSpecs []string `json:"package-specs"`
ExcludSpecs []string `json:"exclude-specs"`
Repos []RepoConfig `json:"repos"`
CacheDir string `json:"cachedir"`
ModulePlatformID string `json:"module_platform_id"`
Clean bool `json:"clean,omitempty"`
}{specs, excludeSpecs, repos, modulePlatformID, clean}
}{specs, excludeSpecs, repos, path.Join(os.Getenv("CACHE_DIRECTORY"), "rpmmd"), modulePlatformID, clean}
var reply struct {
Checksums map[string]string `json:"checksums"`
Dependencies []PackageSpec `json:"dependencies"`