Skip to content

Commit

Permalink
cache: Don't use checksum as filename
Browse files Browse the repository at this point in the history
In some cases (e.g in Pungi), the metadata is changing all the time, fus
is run multiple times a day and the cache just grows. So instead of
using checksum we use the reponame passed in the command line invocation
and the metadata type to create a filename so that only one copy exists
for that reponame. Therefore the cache layout now is:

$CACHEDIR/fus/$reponame/repodata/repomd.xml
$CACHEDIR/fus/$reponame/repodata/primary.xml.gz
$CACHEDIR/fus/$reponame/repodata/modules.xml.gz $CACHEDIR/fus/$reponame/repodata/group_gz.x86_64.xml.xz
$CACHEDIR/fus/$reponame/repodata/filelists.xml.gz

Fixes fedora-modularity#71

Signed-off-by: Rafael Fonseca <[email protected]>
  • Loading branch information
r4f4 committed Aug 14, 2019
1 parent d2b51e0 commit d3f3d8e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions fus.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,22 +515,25 @@ download_repo_metadata (SoupSession *session,
const char *cachedir)
{
Id chksumtype;
const char *fpath, *fname;
const unsigned char *chksum;

fname = repomd_find (repo, type, &chksum, &chksumtype);
if (!fname)
const char *mdname = repomd_find (repo, type, &chksum, &chksumtype);
if (!mdname)
return NULL;

fpath = pool_tmpjoin (repo->pool, cachedir, "/", fname);
/* mdname should be "repodata/$(chksum)-$(type).xml.gz" */
const char *ext = strchr (mdname, '.');
const char *fpath = pool_tmpjoin (repo->pool, cachedir, "/", type);
fpath = pool_tmpappend (repo->pool, fpath, ext, 0);

if (!g_file_test (fpath, G_FILE_TEST_IS_REGULAR) ||
!checksum_matches (fpath, chksum, chksumtype))
{
g_autoptr(GError) error = NULL;
const char *furl = pool_tmpjoin (repo->pool, repo_url, "/", fname);
if (!download_to_path (session, furl, fpath, &error))
const char *mdurl = pool_tmpjoin (repo->pool, repo_url, "/", mdname);
if (!download_to_path (session, mdurl, fpath, &error))
{
g_warning ("Could not download %s: %s", furl, error->message);
g_warning ("Could not download %s: %s", mdurl, error->message);
return NULL;
}
}
Expand All @@ -557,7 +560,8 @@ filelist_loadcb (Pool *pool,
return 0;

g_autofree gchar *cachedir = g_build_filename (g_get_user_cache_dir (),
"fus", repo->name, NULL);
"fus", repo->name, "repodata",
NULL);

fname = download_repo_metadata (session, repo, type, path, cachedir);
fp = solv_xfopen (fname, 0);
Expand Down Expand Up @@ -619,17 +623,17 @@ create_repo (Pool *pool,
repo_add_repomdxml (repo, fp, 0);
fclose (fp);

fname = download_repo_metadata (session, repo, "primary", path, cachedir);
fname = download_repo_metadata (session, repo, "primary", path, destdir);
fp = solv_xfopen (fname, "r");
if (fp != NULL)
{
repo_add_rpmmd (repo, fp, NULL, 0);
fclose (fp);
}

fname = download_repo_metadata (session, repo, "group_gz", path, cachedir);
fname = download_repo_metadata (session, repo, "group_gz", path, destdir);
if (!fname)
fname = download_repo_metadata (session, repo, "group", path, cachedir);
fname = download_repo_metadata (session, repo, "group", path, destdir);
fp = solv_xfopen (fname, "r");
if (fp != NULL)
{
Expand All @@ -656,7 +660,7 @@ create_repo (Pool *pool,

pool_createwhatprovides (pool);

fname = download_repo_metadata (session, repo, "modules", path, cachedir);
fname = download_repo_metadata (session, repo, "modules", path, destdir);
fp = solv_xfopen (fname, "r");
if (fp != NULL)
{
Expand Down

0 comments on commit d3f3d8e

Please sign in to comment.