aboutsummaryrefslogtreecommitdiff
path: root/client/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/file.c')
-rw-r--r--client/file.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/client/file.c b/client/file.c
index 5002d01..8e16103 100644
--- a/client/file.c
+++ b/client/file.c
@@ -40,9 +40,13 @@ write_file(const char *name, const void *data, size_t length)
die("write to %s truncated", temp);
if (close(fd) < 0)
sysdie("close of %s failed (file probably truncated)", temp);
- if (access(name, F_OK) == 0)
+ if (access(name, F_OK) == 0) {
+ if (access(backup, F_OK) == 0)
+ if (unlink(backup) < 0)
+ sysdie("unlink of old backup %s failed", backup);
if (link(name, backup) < 0)
sysdie("link of %s to %s failed", name, backup);
+ }
if (rename(temp, name) < 0)
sysdie("rename of %s to %s failed", temp, name);
free(temp);