summaryrefslogtreecommitdiff
path: root/backup.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2004-05-04 03:10:45 +0000
committerWayne Davison <wayned@samba.org>2004-05-04 03:10:45 +0000
commit377dbd207556fe8e0bca2387205b4e06d9ed23e1 (patch)
tree25511f0cac6a7c0b6bb77069dc3b184a4cfdb356 /backup.c
parent93272700d2eb85320ddf67f3bc1281dbe402f9f9 (diff)
downloadrsync-377dbd207556fe8e0bca2387205b4e06d9ed23e1.tar.gz
Calls to make_bak_dir() should only happen when we fail to create a
file/dir/etc. with errno == ENOENT.
Diffstat (limited to 'backup.c')
-rw-r--r--backup.c22
1 files 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));
}