fetch: always use O_EXCL when creating output files, use unlink if -O is specified
authorFelix Fietkau <nbd@openwrt.org>
Thu, 8 May 2014 15:39:51 +0000 (17:39 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 8 May 2014 15:39:51 +0000 (17:39 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
uclient-fetch.c

index 632cdbb..1644921 100644 (file)
@@ -49,7 +49,7 @@ static int open_output_file(const char *path, bool create)
        int ret;
 
        if (create)
-               flags |= O_CREAT;
+               flags |= O_CREAT | O_EXCL;
 
        if (output_file) {
                if (!strcmp(output_file, "-"))
@@ -58,13 +58,10 @@ static int open_output_file(const char *path, bool create)
                if (!quiet)
                        fprintf(stderr, "Writing to stdout\n");
 
+               unlink(output_file);
                return open(output_file, flags, 0644);
        }
 
-       /* Don't automatically overwrite files if the name is derived from the URL */
-       if (create)
-               flags |= O_EXCL;
-
        filename = uclient_get_url_filename(path, "index.html");
        if (!quiet)
                fprintf(stderr, "Writing to '%s'\n", filename);