summaryrefslogtreecommitdiff
path: root/backup.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2004-07-22 22:52:39 +0000
committerWayne Davison <wayned@samba.org>2004-07-22 22:52:39 +0000
commit394bcdb5e34b3eb7d34f04ad2285a3b289d9f318 (patch)
treec9d9deb753d04a3b2858cac94251ffbe0f6d396f /backup.c
parent28deecca55ff109d6eff7fc09bac7843559b7d5c (diff)
downloadrsync-394bcdb5e34b3eb7d34f04ad2285a3b289d9f318.tar.gz
rsync-394bcdb5e34b3eb7d34f04ad2285a3b289d9f318.tar.bz2
rsync-394bcdb5e34b3eb7d34f04ad2285a3b289d9f318.zip
If we sucessfully renamed a file that has multiple links to it, unlink()
it to ensure that rename() didn't lie to us (which it does if you try to rename() a file over another link to the same file).
Diffstat (limited to 'backup.c')
-rw-r--r--backup.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/backup.c b/backup.c
index b2f6de0e..ed08fae6 100644
--- a/backup.c
+++ b/backup.c
@@ -158,7 +158,8 @@ static int keep_backup(char *fname)
file = make_file(fname, NULL, NO_EXCLUDES);
/* the file could have disappeared */
- if (!file) return 1;
+ if (!file)
+ return 1;
/* make a complete pathname for backup file */
if (stringjoin(backup_dir_buf + backup_dir_len, backup_dir_remainder,
@@ -234,6 +235,10 @@ static int keep_backup(char *fname)
if (robust_move(fname, backup_dir_buf) != 0) {
rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
full_fname(fname), backup_dir_buf);
+ } else if (st.st_nlink > 1) {
+ /* If someone has hard-linked the file into the backup
+ * dir, rename() can return success but do nothing! */
+ robust_unlink(fname); /* Just in case... */
}
}
set_perms(backup_dir_buf, file, NULL, 0);