]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Remove temporary file voodoo
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 Mar 2021 16:17:16 +0000 (16:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 Mar 2021 16:17:16 +0000 (16:17 +0000)
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 <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index e8e2aa2f273a1bc4357a1d4b7253e955f5024d35..b74d50a8f336e72d3162956eb710150a6c98f112 100644 (file)
@@ -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;
 }