]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
util: Use our custom mktemp function everywhere
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 30 Apr 2021 08:01:11 +0000 (08:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 30 Apr 2021 08:01:11 +0000 (08:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c
src/libpakfire/packager.c

index 1c9fbfaacc1293c9211549a7f359e4a970f13070..cf09874b8622e182664996bcf82575f07a481bb8 100644 (file)
@@ -341,13 +341,10 @@ PAKFIRE_EXPORT int pakfire_dist(Pakfire pakfire, const char* path, const char* t
        snprintf(tempfile, PATH_MAX - 1, "%s/.pakfire-dist.XXXXXX", target);
 
        // Create a temporary result file
-       int fd = mkostemp(tempfile, O_CLOEXEC);
-       if (fd < 0)
+       FILE* f = pakfire_mktemp(tempfile);
+       if (!f)
                goto ERROR;
 
-       // Re-open as file handle
-       FILE* f = fdopen(fd, "w");
-
        // Write the finished package
        r = pakfire_packager_finish(packager, f);
        if (r) {
index 634f8e3b3489c29eaaa889b9b6695a3fd3f6d4a9..8b2cf2ba65931019f003b9e69bcf4f78bbe77da9 100644 (file)
@@ -41,6 +41,7 @@
 #include <pakfire/private.h>
 #include <pakfire/pwd.h>
 #include <pakfire/types.h>
+#include <pakfire/util.h>
 
 #define BUFFER_SIZE 64 * 1024
 
@@ -100,23 +101,13 @@ static int pakfire_packager_create_payload(struct pakfire_packager* p) {
        }
 
        // Create a new temporary file
-       int fd = mkostemp(path, O_CLOEXEC);
-       if (fd < 0) {
-               ERROR(p->pakfire, "mkostemp() failed: %s\n", strerror(errno));
+       p->fpayload = pakfire_mktemp(path);
+       if (!p->fpayload)
                return 1;
-       }
 
        // Unlink the file straight away
        unlink(path);
 
-       // Convert the file descriptor into a file handle
-       p->fpayload = fdopen(fd, "w+");
-       if (!p->fpayload) {
-               close(fd);
-
-               return 1;
-       }
-
        // Write archive to file
        r = archive_write_open_FILE(p->payload, p->fpayload);
        if (r)