prune: Handle no-builds case when cleaning pkgcache
I don't recall exactly how I hit this, but basically `cosa fetch`
was failing for me because I had no builds, and we were trying
to look at `builds/latest`.
Fix the prune code here to handle the case where there are no
builds.
@@ -66,11 +66,17 @@ def nevra_to_cache_branch(pkg):
if args.pkgcache:
arch = cmdlib.get_basearch()
+ builds = []
+ if os.path.isfile('builds/builds.json'):
+ with open('builds/builds.json') as f:
+ builds = json.load(f)['builds']
+ build_pkg = []
+ if len(builds) > 0:
+ latest_build = builds[0]
metapath = f"builds/latest/{arch}/commitmeta.json"
with open(metapath) as f:
meta = json.load(f)
build_pkg_nevra = meta['rpmostree.rpmdb.pkglist']
- build_pkg = []
for pkg in build_pkg_nevra:
cache_branch = nevra_to_cache_branch(pkg)
build_pkg.append(cache_branch)
