From 5a6775be4fdbee0523a573af960568ca21f38c49 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Fri, 7 Dec 2007 00:26:24 +0000 Subject: 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. --- client/file.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'client') 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); -- cgit v1.2.3