]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
Avoid creating even the top-level backup dir until needed.
authorWayne Davison <wayned@samba.org>
Mon, 24 Aug 2015 03:58:04 +0000 (20:58 -0700)
committerWayne Davison <wayned@samba.org>
Mon, 24 Aug 2015 04:58:18 +0000 (21:58 -0700)
Fixes bug 11423.

backup.c
main.c

index fcc1a72b90c8a56ab3da4a7cdc88982b3ca54390..bc5e9273e6d2ee55dfb78b53e4c019c60c12cc06 100644 (file)
--- a/backup.c
+++ b/backup.c
@@ -157,6 +157,18 @@ static BOOL copy_valid_path(const char *fname)
 char *get_backup_name(const char *fname)
 {
        if (backup_dir) {
+               static int initialized = 0;
+               if (!initialized) {
+                       int ret;
+                       if (backup_dir_len > 1)
+                               backup_dir_buf[backup_dir_len-1] = '\0';
+                       ret = make_path(backup_dir_buf, 0);
+                       if (backup_dir_len > 1)
+                               backup_dir_buf[backup_dir_len-1] = '/';
+                       if (ret < 0)
+                               return NULL;
+                       initialized = 1;
+               }
                /* copy fname into backup_dir_buf while validating the dirs. */
                if (copy_valid_path(fname))
                        return backup_dir_buf;
diff --git a/main.c b/main.c
index 3a0b702a83a405ce40557c2c0af734472c124f6c..4613c96235ecf263810e08123aada86033d70816 100644 (file)
--- a/main.c
+++ b/main.c
@@ -76,6 +76,7 @@ extern size_t bwlimit_writemax;
 extern unsigned int module_dirlen;
 extern BOOL flist_receiving_enabled;
 extern BOOL shutting_down;
+extern int backup_dir_len;
 extern int basis_dir_cnt;
 extern struct stats stats;
 extern char *stdout_format;
@@ -850,13 +851,25 @@ static int do_recv(int f_in, int f_out, char *local_name)
        }
 
        if (backup_dir) {
-               int ret = make_path(backup_dir_buf, MKP_DROP_NAME); /* drops trailing slash */
-               if (ret < 0)
-                       exit_cleanup(RERR_SYNTAX);
-               if (ret)
-                       rprintf(FINFO, "Created backup_dir %s\n", backup_dir_buf);
-               else if (INFO_GTE(BACKUP, 1))
+               STRUCT_STAT st;
+               int ret;
+               if (backup_dir_len > 1)
+                       backup_dir_buf[backup_dir_len-1] = '\0';
+               ret = do_stat(backup_dir_buf, &st);
+               if (ret != 0 || !S_ISDIR(st.st_mode)) {
+                       if (ret == 0) {
+                               rprintf(FERROR, "The backup-dir is not a directory: %s\n", backup_dir_buf);
+                               exit_cleanup(RERR_SYNTAX);
+                       }
+                       if (errno != ENOENT) {
+                               rprintf(FERROR, "Failed to stat %s: %s\n", backup_dir_buf, strerror(errno));
+                               exit_cleanup(RERR_FILEIO);
+                       }
+                       rprintf(FINFO, "(new) backup_dir is %s\n", backup_dir_buf);
+               } else if (INFO_GTE(BACKUP, 1))
                        rprintf(FINFO, "backup_dir is %s\n", backup_dir_buf);
+               if (backup_dir_len > 1)
+                       backup_dir_buf[backup_dir_len-1] = '/';
        }
 
        io_flush(FULL_FLUSH);