X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/d62bcc17f303f30d1e3df1051b1390202a21cf9c..394bcdb5e34b3eb7d34f04ad2285a3b289d9f318:/backup.c diff --git a/backup.c b/backup.c index 2c69acd1..ed08fae6 100644 --- a/backup.c +++ b/backup.c @@ -98,7 +98,7 @@ static int make_bak_dir(char *fullpath) if (p >= rel) { /* Try to transfer the directory settings of the * actual dir that the files are coming from. */ - if (do_lstat(rel, &st) != 0) { + if (do_stat(rel, &st) < 0) { rsyserr(FERROR, errno, "make_bak_dir stat %s failed", full_fname(rel)); @@ -148,15 +148,18 @@ static int keep_backup(char *fname) /* return if no file to keep */ #if SUPPORT_LINKS - if (do_lstat(fname, &st)) return 1; + ret_code = do_lstat(fname, &st); #else - if (do_stat(fname, &st)) return 1; + ret_code = do_stat(fname, &st); #endif + if (ret_code < 0) + return 1; 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, @@ -232,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);