summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorFabian Keil <fk@fabiankeil.de>2016-11-12 15:40:10 +0100
committerDavid Goulet <dgoulet@torproject.org>2016-11-16 11:25:26 -0500
commitdb2dd8434e84b54b4196cd7e804ceae13f0c5ea7 (patch)
treebbd1ad74f6b4fdd90084b61b8f471712f397a613 /src/common/util.c
parent9a790f7325049fdb3b48e86879cd05373cbcd1e3 (diff)
downloadtor-db2dd8434e84b54b4196cd7e804ceae13f0c5ea7.tar.gz
tor-db2dd8434e84b54b4196cd7e804ceae13f0c5ea7.zip
finish_writing_to_file_impl(): Remove temporary file if replacing the existing one failed
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/common/util.c b/src/common/util.c
index cb5f12821e..3421d117b0 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2601,6 +2601,14 @@ finish_writing_to_file_impl(open_file_t *file_data, int abort_write)
if (file_data->rename_on_close) {
tor_assert(file_data->tempname && file_data->filename);
+ if (!abort_write) {
+ tor_assert(strcmp(file_data->filename, file_data->tempname));
+ if (replace_file(file_data->tempname, file_data->filename)) {
+ log_warn(LD_FS, "Error replacing \"%s\": %s", file_data->filename,
+ strerror(errno));
+ abort_write = r = -1;
+ }
+ }
if (abort_write) {
int res = unlink(file_data->tempname);
if (res != 0) {
@@ -2609,13 +2617,6 @@ finish_writing_to_file_impl(open_file_t *file_data, int abort_write)
file_data->tempname, strerror(errno));
r = -1;
}
- } else {
- tor_assert(strcmp(file_data->filename, file_data->tempname));
- if (replace_file(file_data->tempname, file_data->filename)) {
- log_warn(LD_FS, "Error replacing \"%s\": %s", file_data->filename,
- strerror(errno));
- r = -1;
- }
}
}