Skip to content

Commit 16bb360

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/$chksum.solv $CACHEDIR/fus/$reponame/$chksum.solvx $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 <r4f4rfs@gmail.com>
1 parent 9cb602f commit 16bb360

1 file changed

Lines changed: 41 additions & 12 deletions

File tree

repo.c

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -510,22 +510,25 @@ download_repo_metadata (SoupSession *session,
510510
const char *cachedir)
511511
{
512512
Id chksumtype;
513-
const char *fpath, *fname;
514513
const unsigned char *chksum;
515514

516-
fname = repomd_find (repo, type, &chksum, &chksumtype);
517-
if (!fname)
515+
const char *mdname = repomd_find (repo, type, &chksum, &chksumtype);
516+
if (!mdname)
518517
return NULL;
519518

520-
fpath = pool_tmpjoin (repo->pool, cachedir, "/", fname);
519+
/* mdname should be "repodata/$(chksum)-$(type).xml.gz" */
520+
const char *ext = strchr (mdname, '.');
521+
const char *fpath = pool_tmpjoin (repo->pool, cachedir, "/", type);
522+
fpath = pool_tmpappend (repo->pool, fpath, ext, 0);
523+
521524
if (!g_file_test (fpath, G_FILE_TEST_IS_REGULAR) ||
522525
!checksum_matches (fpath, chksum, chksumtype))
523526
{
524527
g_autoptr(GError) error = NULL;
525-
const char *furl = pool_tmpjoin (repo->pool, repo_url, "/", fname);
526-
if (!download_to_path (session, furl, fpath, &error))
528+
const char *mdurl = pool_tmpjoin (repo->pool, repo_url, "/", mdname);
529+
if (!download_to_path (session, mdurl, fpath, &error))
527530
{
528-
g_warning ("Could not download %s: %s", furl, error->message);
531+
g_warning ("Could not download %s: %s", mdurl, error->message);
529532
return NULL;
530533
}
531534
}
@@ -643,6 +646,25 @@ get_repo_cachedir (const char *name)
643646
return g_build_filename (g_get_user_cache_dir (), "fus", name, NULL);
644647
}
645648

649+
static void
650+
remove_files_by_ext (const char *dirpath,
651+
const char *ext)
652+
{
653+
g_autoptr(GDir) dir = g_dir_open (dirpath, 0, NULL);
654+
if (!dir)
655+
return;
656+
657+
const gchar *fname;
658+
while ((fname = g_dir_read_name (dir)) != NULL)
659+
{
660+
if (g_str_has_suffix (fname, ext))
661+
{
662+
g_autofree gchar *path = g_build_filename (dirpath, fname, NULL);
663+
g_unlink (path);
664+
}
665+
}
666+
}
667+
646668
int
647669
filelist_loadcb (Pool *pool,
648670
Repodata *data,
@@ -668,11 +690,15 @@ filelist_loadcb (Pool *pool,
668690
return 1;
669691
}
670692

693+
/* Cleanup old libsolv cache files (if any) */
694+
remove_files_by_ext (cachedir, ".solvx");
695+
671696
path = repodata_lookup_str (data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
672697
if (!path)
673698
return 0;
674699

675-
fname = download_repo_metadata (session, repo, type, path, cachedir);
700+
const char *destdir = pool_tmpjoin (pool, cachedir, "/", "repodata");
701+
fname = download_repo_metadata (session, repo, type, path, destdir);
676702
fp = solv_xfopen (fname, 0);
677703
if (!fp)
678704
{
@@ -747,20 +773,23 @@ create_repo (Pool *pool,
747773
return repo;
748774
}
749775

776+
/* Cleanup old libsolv cache files (if any) */
777+
remove_files_by_ext (cachedir, ".solv");
778+
750779
repo_add_repomdxml (repo, fp, 0);
751780
fclose (fp);
752781

753-
fname = download_repo_metadata (session, repo, "primary", path, cachedir);
782+
fname = download_repo_metadata (session, repo, "primary", path, destdir);
754783
fp = solv_xfopen (fname, "r");
755784
if (fp != NULL)
756785
{
757786
repo_add_rpmmd (repo, fp, NULL, 0);
758787
fclose (fp);
759788
}
760789

761-
fname = download_repo_metadata (session, repo, "group_gz", path, cachedir);
790+
fname = download_repo_metadata (session, repo, "group_gz", path, destdir);
762791
if (!fname)
763-
fname = download_repo_metadata (session, repo, "group", path, cachedir);
792+
fname = download_repo_metadata (session, repo, "group", path, destdir);
764793
fp = solv_xfopen (fname, "r");
765794
if (fp != NULL)
766795
{
@@ -786,7 +815,7 @@ create_repo (Pool *pool,
786815

787816
pool_createwhatprovides (pool);
788817

789-
fname = download_repo_metadata (session, repo, "modules", path, cachedir);
818+
fname = download_repo_metadata (session, repo, "modules", path, destdir);
790819
fp = solv_xfopen (fname, "r");
791820
if (fp != NULL)
792821
{

0 commit comments

Comments
 (0)