From e350ca4e73771c5a23e08ecc25ea4d3a966e51f8 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 8 May 2014 17:39:51 +0200 Subject: [PATCH] fetch: always use O_EXCL when creating output files, use unlink if -O is specified Signed-off-by: Felix Fietkau --- uclient-fetch.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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); -- 2.25.1