Merge remote-tracking branch 'dgoulet/bug20646_030_01'

This commit is contained in:
Nick Mathewson 2016-11-17 20:08:00 -05:00
commit b7db39e88a
2 changed files with 13 additions and 7 deletions

5
changes/bug20646 Normal file
View File

@ -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.

View File

@ -2601,6 +2601,14 @@ finish_writing_to_file_impl(open_file_t *file_data, int abort_write)
if (file_data->rename_on_close) { if (file_data->rename_on_close) {
tor_assert(file_data->tempname && file_data->filename); 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) { if (abort_write) {
int res = unlink(file_data->tempname); int res = unlink(file_data->tempname);
if (res != 0) { 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)); file_data->tempname, strerror(errno));
r = -1; 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;
}
} }
} }