mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-05-05 21:45:22 -04:00
Calls to make_bak_dir() should only happen when we fail to create a
file/dir/etc. with errno == ENOENT.
This commit is contained in:
22
backup.c
22
backup.c
@@ -33,6 +33,7 @@ extern int preserve_devices;
|
||||
extern int preserve_links;
|
||||
extern int preserve_hard_links;
|
||||
extern int orig_umask;
|
||||
extern int safe_symlinks;
|
||||
|
||||
/* simple backup creates a backup with a suffix in the same directory */
|
||||
static int make_simple_backup(char *fname)
|
||||
@@ -169,8 +170,9 @@ static int keep_backup(char *fname)
|
||||
/* Check to see if this is a device file, or link */
|
||||
if (IS_DEVICE(file->mode)) {
|
||||
if (am_root && preserve_devices) {
|
||||
make_bak_dir(backup_dir_buf);
|
||||
if (do_mknod(backup_dir_buf, file->mode, file->u.rdev) != 0) {
|
||||
if (do_mknod(backup_dir_buf, file->mode, file->u.rdev) < 0
|
||||
&& (errno != ENOENT || make_bak_dir(backup_dir_buf) < 0
|
||||
|| do_mknod(backup_dir_buf, file->mode, file->u.rdev) < 0)) {
|
||||
rprintf(FERROR, "mknod %s failed: %s\n",
|
||||
full_fname(backup_dir_buf), strerror(errno));
|
||||
} else if (verbose > 2) {
|
||||
@@ -186,10 +188,14 @@ static int keep_backup(char *fname)
|
||||
|
||||
if (!kept && S_ISDIR(file->mode)) {
|
||||
/* make an empty directory */
|
||||
make_bak_dir(backup_dir_buf);
|
||||
do_mkdir(backup_dir_buf, file->mode);
|
||||
ret_code = do_rmdir(fname);
|
||||
if (do_mkdir(backup_dir_buf, file->mode) < 0
|
||||
&& (errno != ENOENT || make_bak_dir(backup_dir_buf) < 0
|
||||
|| do_mkdir(backup_dir_buf, file->mode) < 0)) {
|
||||
rprintf(FINFO, "mkdir %s failed: %s\n",
|
||||
full_fname(backup_dir_buf), strerror(errno));
|
||||
}
|
||||
|
||||
ret_code = do_rmdir(fname);
|
||||
if (verbose > 2) {
|
||||
rprintf(FINFO, "make_backup: RMDIR %s returns %i\n",
|
||||
full_fname(fname), ret_code);
|
||||
@@ -199,7 +205,6 @@ static int keep_backup(char *fname)
|
||||
|
||||
#if SUPPORT_LINKS
|
||||
if (!kept && preserve_links && S_ISLNK(file->mode)) {
|
||||
extern int safe_symlinks;
|
||||
if (safe_symlinks && unsafe_symlink(file->u.link, backup_dir_buf)) {
|
||||
if (verbose) {
|
||||
rprintf(FINFO, "ignoring unsafe symlink %s -> %s\n",
|
||||
@@ -207,8 +212,9 @@ static int keep_backup(char *fname)
|
||||
}
|
||||
kept = 1;
|
||||
}
|
||||
make_bak_dir(backup_dir_buf);
|
||||
if (do_symlink(file->u.link, backup_dir_buf) != 0) {
|
||||
if (do_symlink(file->u.link, backup_dir_buf) < 0
|
||||
&& (errno != ENOENT || make_bak_dir(backup_dir_buf) < 0
|
||||
|| do_symlink(file->u.link, backup_dir_buf) < 0)) {
|
||||
rprintf(FERROR, "link %s -> %s : %s\n",
|
||||
full_fname(backup_dir_buf), file->u.link, strerror(errno));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user