aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorKevin Butler <haqkrs@gmail.com>2013-09-01 00:24:07 +0100
committerKevin Butler <haqkrs@gmail.com>2013-09-01 00:24:07 +0100
commit1bdb391ed0df979bc29ed1b62e7c0f3c9494a8d7 (patch)
tree1fc47f453def9cba2da8294236a26613ad0163bc /src/common/util.c
parent00bcc25d05dc0273323a2cae20c6aa62afd4b50a (diff)
downloadtor-1bdb391ed0df979bc29ed1b62e7c0f3c9494a8d7.tar
tor-1bdb391ed0df979bc29ed1b62e7c0f3c9494a8d7.tar.gz
Added no_tempfile parameter to write_chunks_to_file to do non-atomic writes. Implements #1376.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 6e14a58dd..4e84d942e 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2190,12 +2190,19 @@ write_chunks_to_file_impl(const char *fname, const smartlist_t *chunks,
return -1;
}
-/** Given a smartlist of sized_chunk_t, write them atomically to a file
- * <b>fname</b>, overwriting or creating the file as necessary. */
+/** Given a smartlist of sized_chunk_t, write them to a file
+ * <b>fname</b>, overwriting or creating the file as necessary.
+ * If <b>no_tempfile</b> is 0 then the file will be written
+ * atomically. */
int
-write_chunks_to_file(const char *fname, const smartlist_t *chunks, int bin)
+write_chunks_to_file(const char *fname, const smartlist_t *chunks, int bin, int no_tempfile)
{
int flags = OPEN_FLAGS_REPLACE|(bin?O_BINARY:O_TEXT);
+
+ if (no_tempfile) {
+ // O_APPEND stops write_chunks_to_file from using tempfiles
+ flags |= O_APPEND;
+ }
return write_chunks_to_file_impl(fname, chunks, flags);
}