From: Felix Fietkau Date: Thu, 8 May 2014 15:39:51 +0000 (+0200) Subject: fetch: always use O_EXCL when creating output files, use unlink if -O is specified X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuclient.git;a=commitdiff_plain;h=e350ca4e73771c5a23e08ecc25ea4d3a966e51f8 fetch: always use O_EXCL when creating output files, use unlink if -O is specified Signed-off-by: Felix Fietkau --- diff --git a/uclient-fetch.c b/uclient-fetch.c index 632cdbb..1644921 100644 --- a/uclient-fetch.c +++ b/uclient-fetch.c @@ -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);