aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-11-17 20:08:00 -0500
committerNick Mathewson <nickm@torproject.org>2016-11-17 20:08:00 -0500
commitb7db39e88ab6d97a5a0a5f1ff7e0d5b73e51e05e (patch)
tree393c0813450f1437abbf985c0f907cf3501ff01a
parentfe711c29448a84d483818c95890de118f13b7e44 (diff)
parent6b13612eef50283af8c52b160553b192eec9ed6e (diff)
downloadtor-b7db39e88ab6d97a5a0a5f1ff7e0d5b73e51e05e.tar.gz
tor-b7db39e88ab6d97a5a0a5f1ff7e0d5b73e51e05e.zip
Merge remote-tracking branch 'dgoulet/bug20646_030_01'
-rw-r--r--changes/bug206465
-rw-r--r--src/common/util.c15
2 files changed, 13 insertions, 7 deletions
diff --git a/changes/bug20646 b/changes/bug20646
new file mode 100644
index 0000000000..42e319ffcb
--- /dev/null
+++ b/changes/bug20646
@@ -0,0 +1,5 @@
+ o Minor bugfix (util)
+ - When finishing writing a file to disk, if we were about to replace the
+ file with the temporary file created before and we fail to replace it,
+ remove the temporary file so it doesn't stay on disk. Closes #20646;
+ bugfix on tor-0.2.0.7-alpha; Patch by fk.
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;
- }
}
}