aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-05-18 15:35:21 +0000
committerNick Mathewson <nickm@torproject.org>2004-05-18 15:35:21 +0000
commit7511fbf993271312875d0648166694cc58117060 (patch)
tree57e08c4ab87356af3149d328cf56582ae8ad54a4 /src/common/util.c
parent9da1714676c018e1b4a8c5b52c7be7a5a6579243 (diff)
downloadtor-7511fbf993271312875d0648166694cc58117060.tar
tor-7511fbf993271312875d0648166694cc58117060.tar.gz
Resolve some XXXs
svn:r1889
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c
index d41b0e272..727af645b 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1323,7 +1323,28 @@ write_str_to_file(const char *fname, const char *str)
return -1;
}
fclose(file);
- /* XXXX This won't work on windows: you can't use rename to replace a file.*/
+
+#ifdef MS_WINDOWS
+ /* On Windows, rename doesn't replace. We could call ReplaceFile, but
+ * that's hard, and we can probably sneak by without atomicity. */
+ switch (file_status(fname)) {
+ case FN_ERROR:
+ log(LOG_WARN, "Error replacing %s: %s", fname, strerror(errno));
+ return -1;
+ case FN_DIR:
+ log(LOG_WARN, "Error replacing %s: is directory", fname);
+ return -1;
+ case FN_FILE:
+ if (unlink(fname)) {
+ log(LOG_WARN, "Error replacing %s while removing old copy: %s",
+ fname, strerror(errno));
+ return -1;
+ }
+ break;
+ case FN_NOENT:
+ ;
+ }
+#endif
if (rename(tempname, fname)) {
log(LOG_WARN, "Error replacing %s: %s", fname, strerror(errno));
return -1;