Skip to content

Commit 930a5fb

Browse files
committed
cache: Don't use checksum as filename
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 #71 Signed-off-by: Rafael Fonseca <[email protected]>
1 parent d2b51e0 commit 930a5fb

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Diff for: fus.c

+16-12
Original file line numberDiff line numberDiff line change
@@ -515,22 +515,25 @@ download_repo_metadata (SoupSession *session,
515515
const char *cachedir)
516516
{
517517
Id chksumtype;
518-
const char *fpath, *fname;
519518
const unsigned char *chksum;
520519

521-
fname = repomd_find (repo, type, &chksum, &chksumtype);
522-
if (!fname)
520+
const char *mdname = repomd_find (repo, type, &chksum, &chksumtype);
521+
if (!mdname)
523522
return NULL;
524523

525-
fpath = pool_tmpjoin (repo->pool, cachedir, "/", fname);
524+
/* mdname should be "repodata/$(chksum)-$(type).xml.gz" */
525+
const char *ext = strchr (mdname, '.');
526+
const char *fpath = pool_tmpjoin (repo->pool, cachedir, "/", type);
527+
fpath = pool_tmpappend (repo->pool, fpath, ext, 0);
528+
526529
if (!g_file_test (fpath, G_FILE_TEST_IS_REGULAR) ||
527530
!checksum_matches (fpath, chksum, chksumtype))
528531
{
529532
g_autoptr(GError) error = NULL;
530-
const char *furl = pool_tmpjoin (repo->pool, repo_url, "/", fname);
531-
if (!download_to_path (session, furl, fpath, &error))
533+
const char *mdurl = pool_tmpjoin (repo->pool, repo_url, "/", mdname);
534+
if (!download_to_path (session, mdurl, fpath, &error))
532535
{
533-
g_warning ("Could not download %s: %s", furl, error->message);
536+
g_warning ("Could not download %s: %s", mdurl, error->message);
534537
return NULL;
535538
}
536539
}
@@ -557,7 +560,8 @@ filelist_loadcb (Pool *pool,
557560
return 0;
558561

559562
g_autofree gchar *cachedir = g_build_filename (g_get_user_cache_dir (),
560-
"fus", repo->name, NULL);
563+
"fus", repo->name, "repodata",
564+
NULL);
561565

562566
fname = download_repo_metadata (session, repo, type, path, cachedir);
563567
fp = solv_xfopen (fname, 0);
@@ -619,17 +623,17 @@ create_repo (Pool *pool,
619623
repo_add_repomdxml (repo, fp, 0);
620624
fclose (fp);
621625

622-
fname = download_repo_metadata (session, repo, "primary", path, cachedir);
626+
fname = download_repo_metadata (session, repo, "primary", path, destdir);
623627
fp = solv_xfopen (fname, "r");
624628
if (fp != NULL)
625629
{
626630
repo_add_rpmmd (repo, fp, NULL, 0);
627631
fclose (fp);
628632
}
629633

630-
fname = download_repo_metadata (session, repo, "group_gz", path, cachedir);
634+
fname = download_repo_metadata (session, repo, "group_gz", path, destdir);
631635
if (!fname)
632-
fname = download_repo_metadata (session, repo, "group", path, cachedir);
636+
fname = download_repo_metadata (session, repo, "group", path, destdir);
633637
fp = solv_xfopen (fname, "r");
634638
if (fp != NULL)
635639
{
@@ -656,7 +660,7 @@ create_repo (Pool *pool,
656660

657661
pool_createwhatprovides (pool);
658662

659-
fname = download_repo_metadata (session, repo, "modules", path, cachedir);
663+
fname = download_repo_metadata (session, repo, "modules", path, destdir);
660664
fp = solv_xfopen (fname, "r");
661665
if (fp != NULL)
662666
{

0 commit comments

Comments
 (0)