Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache: Don't use checksum as filename #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,22 +510,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 Down Expand Up @@ -643,6 +646,25 @@ get_repo_cachedir (const char *name)
return g_build_filename (g_get_user_cache_dir (), "fus", name, NULL);
}

static void
remove_files_by_ext (const char *dirpath,
const char *ext)
{
g_autoptr(GDir) dir = g_dir_open (dirpath, 0, NULL);
if (!dir)
return;

const gchar *fname;
while ((fname = g_dir_read_name (dir)) != NULL)
{
if (g_str_has_suffix (fname, ext))
{
g_autofree gchar *path = g_build_filename (dirpath, fname, NULL);
g_unlink (path);
}
}
}

int
filelist_loadcb (Pool *pool,
Repodata *data,
Expand All @@ -668,11 +690,15 @@ filelist_loadcb (Pool *pool,
return 1;
}

/* Cleanup old libsolv cache files (if any) */
remove_files_by_ext (cachedir, ".solvx");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really bad idea. that means, if you use even same repo with same metadata, you always remove stuff which is unrelated. I think we should not do this…

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I can load previous libsolv cache, I don't execute this code (see previous if with return 1).
I just remove the solv files in case I couldn't load previous cache for the same metadata, in which case the metadata has changed. If I don't do that, the libsolv cache will only grow because we'll create a new file every time the metadata changes for that repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless it's not a problem that .solv[x] files are never removed.


path = repodata_lookup_str (data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
if (!path)
return 0;

fname = download_repo_metadata (session, repo, type, path, cachedir);
const char *destdir = pool_tmpjoin (pool, cachedir, "/", "repodata");
fname = download_repo_metadata (session, repo, type, path, destdir);
fp = solv_xfopen (fname, 0);
if (!fp)
{
Expand Down Expand Up @@ -747,20 +773,23 @@ create_repo (Pool *pool,
return repo;
}

/* Cleanup old libsolv cache files (if any) */
remove_files_by_ext (cachedir, ".solv");

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 @@ -786,7 +815,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