]> git.ipfire.org Git - pakfire.git/commitdiff
util: touch: Actually set mode
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Nov 2022 14:16:26 +0000 (14:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Nov 2022 14:16:26 +0000 (14:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/util.c

index 7ce4d1e0c2eff91fc59ad8af3d705de43f2b5022..0fd7406da21d61e253674dcf05c851e35dab7b50 100644 (file)
@@ -374,11 +374,26 @@ int __pakfire_unhexlify(unsigned char* dst, const size_t l, const char* src) {
 }
 
 int pakfire_touch(const char* path, mode_t mode) {
+       int r = 1;
+
        FILE* f = fopen(path, "w");
        if (!f)
-               return 1;
+               goto ERROR;
+
+       // Set the requested mode
+       if (mode) {
+               r = fchmod(fileno(f), mode);
+               if (r)
+                       goto ERROR;
+       }
 
        return fclose(f);
+
+ERROR:
+       if (f)
+               fclose(f);
+
+       return r;
 }
 
 int pakfire_mkparentdir(const char* path, mode_t mode) {