From 377dbd207556fe8e0bca2387205b4e06d9ed23e1 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Tue, 4 May 2004 03:10:45 +0000 Subject: [PATCH] Calls to make_bak_dir() should only happen when we fail to create a file/dir/etc. with errno == ENOENT. --- backup.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/backup.c b/backup.c index 43bba13b..db21fb1a 100644 --- a/backup.c +++ b/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)); } -- 2.34.1