]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
util: Allow setting file mode for temporary files
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Nov 2022 18:38:29 +0000 (18:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Nov 2022 18:38:29 +0000 (18:38 +0000)
Fixes: #12974
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
src/libpakfire/downloader.c
src/libpakfire/include/pakfire/util.h
src/libpakfire/packager.c
src/libpakfire/repo.c
src/libpakfire/request.c
src/libpakfire/util.c

index c669b3abbcceaac1c17fc75c439203601bceebaa..c5651f58fbb373ef06007a25cf7a58d0d6b074ec 100644 (file)
@@ -233,7 +233,7 @@ static int pakfire_build_find_dependencies(struct pakfire_build* build,
                return 1;
 
        // Create a temporary file
-       FILE* f = pakfire_mktemp(path);
+       FILE* f = pakfire_mktemp(path, 0);
        if (!f)
                goto ERROR;
 
@@ -408,7 +408,7 @@ static int pakfire_build_add_scriptlet_requires(struct pakfire_build* build,
        const char* data = pakfire_scriptlet_get_data(scriptlet, &size);
 
        // Create a temporary file
-       FILE* f = pakfire_mktemp(path);
+       FILE* f = pakfire_mktemp(path, 0);
        if (!f)
                return 1;
 
index 113eb3b1be162fc089c8c3e8f80c81591ade58cc..25086512d9a71a1a459c44c5201c9e026a9139a5 100644 (file)
@@ -765,7 +765,7 @@ static int pakfire_downloader_prepare_transfer(struct pakfire_downloader* downlo
                if (r)
                        return 1;
 
-               transfer->f = pakfire_mktemp(transfer->tempfile);
+               transfer->f = pakfire_mktemp(transfer->tempfile, 0);
                if (!transfer->f) {
                        ERROR(downloader->pakfire, "Could not create temporary file for download %s: %m\n",
                                transfer->tempfile);
index 944cd5e6a6590198307952dc42e53f5c970308c4..3d627d1e46f005ee85dd45e615973cd7caf362a0 100644 (file)
@@ -66,7 +66,7 @@ int pakfire_file_write(struct pakfire* pakfire, const char* path,
 int pakfire_touch(const char* path, mode_t mode);
 int pakfire_mkparentdir(const char* path, mode_t mode);
 int pakfire_mkdir(const char* path, mode_t mode);
-FILE* pakfire_mktemp(char* path);
+FILE* pakfire_mktemp(char* path, const mode_t mode);
 char* pakfire_mkdtemp(char* path);
 int pakfire_rmtree(const char* path, int flags);
 
index f2161be69f541e31c0799952ca677f40e0068a3d..812c257257a47b3d17826497d5cbd5b2d7c9cfaa 100644 (file)
@@ -548,7 +548,7 @@ int pakfire_packager_finish_to_directory(struct pakfire_packager* packager,
                goto ERROR;
 
        // Create a temporary result file
-       f = pakfire_mktemp(tmppath);
+       f = pakfire_mktemp(tmppath, 0);
        if (!f)
                goto ERROR;
 
index 548828bd1a9360420f2dbd7fb094c7cc656a7c56..619166e95f10c89150a09290c10233903127c178 100644 (file)
@@ -1235,7 +1235,7 @@ static int pakfire_repo_write_database(struct pakfire_repo* repo, const char* pa
                return r;
 
        // Create a temporary file to write to
-       FILE* f = pakfire_mktemp(tmp);
+       FILE* f = pakfire_mktemp(tmp, 0644);
        if (!f) {
                ERROR(repo->pakfire, "Could not open temporary file for writing: %m\n");
                return 1;
index 2206e196d2046c609c96c5765b43f509b34d2837..e18a2d7bc04d3c2a44676e76b23d21ba80a1e620 100644 (file)
@@ -414,7 +414,7 @@ static int pakfire_request_add_url(struct pakfire_request* request, int action,
        char path[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-download.XXXXXX";
 
        // Allocate a temporary file name
-       FILE* f = pakfire_mktemp(path);
+       FILE* f = pakfire_mktemp(path, 0);
        if (!f)
                return 1;
 
index f814962642b08597dfa57c62a65f5c8a482cd049..21bd2d49de0bf6f60297a594f0ecb9ecfd340be9 100644 (file)
@@ -450,7 +450,7 @@ int pakfire_mkdir(const char* path, mode_t mode) {
        return pakfire_try_mkdir(path, mode);
 }
 
-FILE* pakfire_mktemp(char* path) {
+FILE* pakfire_mktemp(char* path, const mode_t mode) {
        int r = pakfire_mkparentdir(path, 0755);
        if (r)
                return NULL;
@@ -460,6 +460,13 @@ FILE* pakfire_mktemp(char* path) {
        if (fd < 0)
                return NULL;
 
+       // Set desired mode
+       if (mode) {
+               r = fchmod(fd, mode);
+               if (r)
+                       return NULL;
+       }
+
        // Re-open as file handle
        return fdopen(fd, "w+");
 }