From: Michael Tremer Date: Sat, 13 Mar 2021 16:17:16 +0000 (+0000) Subject: repo: Remove temporary file voodoo X-Git-Tag: 0.9.28~1285^2~533 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a290161328408fc55a18685c04d6d57902b8c94;p=pakfire.git repo: Remove temporary file voodoo This will now overwrite any files with invalid content if that is being received from the server. This isn't ideal but good enough for now. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index e8e2aa2f2..b74d50a8f 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -189,18 +189,15 @@ ERROR: } static int pakfire_repo_refresh_mirrorlist(PakfireRepo repo, const int force) { - const char* mirrorlist_url = repo->appdata->mirrorlist_url; - const char* mirrorlist = repo->appdata->mirrorlist; int r; - char path[PATH_MAX]; // This repository does not have a mirrorlist - if (!mirrorlist_url || !*mirrorlist) + if (!repo->appdata->mirrorlist_url || !*repo->appdata->mirrorlist) return 0; // Check if this needs to be refreshed if (!force) { - time_t age = pakfire_path_age(mirrorlist); + time_t age = pakfire_path_age(repo->appdata->mirrorlist); if (age > 0 && age < REFRESH_AGE_MIRRORLIST) { DEBUG(repo->pakfire, "Skip refreshing mirrorlist which is %lds old\n", age); @@ -213,30 +210,16 @@ static int pakfire_repo_refresh_mirrorlist(PakfireRepo repo, const int force) { if (!downloader) return 1; - // Make download path - snprintf(path, sizeof(path) - 1, "%s/repodata/%s/.mirrorlist", - pakfire_get_cache_path(repo->pakfire), pakfire_repo_get_name(repo)); - // Try to retrieve the mirrorlist - r = pakfire_downloader_retrieve(downloader, mirrorlist_url, path); + r = pakfire_downloader_retrieve(downloader, + repo->appdata->mirrorlist_url, repo->appdata->mirrorlist); if (r) goto ERROR; // Parse it - r = pakfire_downloader_read_mirrorlist(downloader, path); - if (r && errno != ENOENT) { - unlink(path); - goto ERROR; - } - - // Drop previous version of the mirrorlist - unlink(mirrorlist); - - // Link the temporary file to the permanent location - r = link(path, mirrorlist); + r = pakfire_downloader_read_mirrorlist(downloader, repo->appdata->mirrorlist); if (r) { - ERROR(repo->pakfire, "Could not write mirrorlist %s: %s\n", - mirrorlist, strerror(errno)); + unlink(repo->appdata->mirrorlist); goto ERROR; } @@ -265,29 +248,24 @@ static int pakfire_repo_refresh_metadata(PakfireRepo repo, const int force) { if (!downloader) return 1; - // Make download path - char path[PATH_MAX]; - snprintf(path, sizeof(path) - 1, "%s/repodata/%s/.repomd.json", - pakfire_get_cache_path(repo->pakfire), pakfire_repo_get_name(repo)); - // Try to download the metadata - int r = pakfire_downloader_retrieve(downloader, "repodata/repomd.json", path); + int r = pakfire_downloader_retrieve(downloader, + "repodata/repomd.json", repo->appdata->metadata); if (r) goto ERROR; // Parse metadata - r = pakfire_repo_read_metadata(repo, path, 1); - if (r) + r = pakfire_repo_read_metadata(repo, repo->appdata->metadata, 1); + if (r) { + unlink(repo->appdata->metadata); goto ERROR; - - // Store repodata permanently + } // Success r = 0; ERROR: pakfire_downloader_unref(downloader); - unlink(path); return 0; }