The branch, master has been updated
       via  abfb41e Avoid creating even the top-level backup dir until needed. 
Fixes bug 11423.
       via  9d1cd24 Improve make_path() error return for non-dir element.
      from  f8d2ecd Preparing for release of 3.1.2pre1

https://git.samba.org/?p=rsync.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit abfb41e63e9c18f05984bad5ac5a627f38b278ed
Author: Wayne Davison <way...@samba.org>
Date:   Sun Aug 23 20:58:04 2015 -0700

    Avoid creating even the top-level backup dir until needed.
    Fixes bug 11423.

commit 9d1cd2437c81dadb5d1a7eff2cec0c529d10289a
Author: Wayne Davison <way...@samba.org>
Date:   Sun Aug 23 20:52:59 2015 -0700

    Improve make_path() error return for non-dir element.

-----------------------------------------------------------------------

Summary of changes:
 backup.c | 12 ++++++++++++
 main.c   | 25 +++++++++++++++++++------
 util.c   |  6 ++++--
 3 files changed, 35 insertions(+), 8 deletions(-)


Changeset truncated at 500 lines:

diff --git a/backup.c b/backup.c
index fcc1a72..bc5e927 100644
--- 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 3a0b702..4613c96 100644
--- 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);
diff --git a/util.c b/util.c
index 0775add..c0e239d 100644
--- a/util.c
+++ b/util.c
@@ -190,7 +190,7 @@ int make_path(char *fname, int flags)
 
        if (flags & MKP_DROP_NAME) {
                end = strrchr(fname, '/');
-               if (!end)
+               if (!end || end == fname)
                        return 0;
                *end = '\0';
        } else
@@ -210,8 +210,10 @@ int make_path(char *fname, int flags)
                        ret++;
                        break;
                }
+
                if (errno != ENOENT) {
-                       if (errno != EEXIST)
+                       STRUCT_STAT st;
+                       if (errno != EEXIST || (do_stat(fname, &st) == 0 && 
!S_ISDIR(st.st_mode)))
                                ret = -ret - 1;
                        break;
                }


-- 
The rsync repository.

_______________________________________________
rsync-cvs mailing list
rsync-cvs@lists.samba.org
https://lists.samba.org/mailman/listinfo/rsync-cvs

Reply via email to