diff options
author | Russ Allbery <rra@stanford.edu> | 2007-12-07 00:26:24 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2007-12-07 00:26:24 +0000 |
commit | 5a6775be4fdbee0523a573af960568ca21f38c49 (patch) | |
tree | a8c0ed31e880143825f8760bc59e27babbe966a7 /client/file.c | |
parent | b21e806902b9d9342c5990e7b42cbe99e98af704 (diff) |
Allow the empty string in wallet-backend arguments.
When writing to a file in the wallet client program, remove an old
backup file before creating a new backup and don't fail if the backup
already exists.
Diffstat (limited to 'client/file.c')
-rw-r--r-- | client/file.c | 6 |
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); |