When running with --fake-super, get/put ACLs from/to an xattr and don't
[rsync/rsync.git] / util.c
diff --git a/util.c b/util.c
index 1fc3106..689de61 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,6 +21,7 @@
  */
 
 #include "rsync.h"
+#include "ifuncs.h"
 
 extern int verbose;
 extern int dry_run;
@@ -90,9 +91,9 @@ int fd_pair(int fd[2])
        return ret;
 }
 
-void print_child_argv(char **cmd)
+void print_child_argv(const char *prefix, char **cmd)
 {
-       rprintf(FCLIENT, "opening connection using ");
+       rprintf(FCLIENT, "%s ", prefix);
        for (; *cmd; cmd++) {
                /* Look for characters that ought to be quoted.  This
                * is not a great quoting algorithm, but it's
@@ -264,15 +265,14 @@ static int safe_read(int desc, char *ptr, size_t len)
  *
  * This is used in conjunction with the --temp-dir, --backup, and
  * --copy-dest options. */
-int copy_file(const char *source, const char *dest, mode_t mode)
+int copy_file(const char *source, const char *dest, mode_t mode, int create_bak_dir)
 {
        int ifd;
        int ofd;
        char buf[1024 * 8];
        int len;   /* Number of bytes read into `buf'. */
 
-       ifd = do_open(source, O_RDONLY, 0);
-       if (ifd == -1) {
+       if ((ifd = do_open(source, O_RDONLY, 0)) < 0) {
                rsyserr(FERROR, errno, "open %s", full_fname(source));
                return -1;
        }
@@ -282,8 +282,9 @@ int copy_file(const char *source, const char *dest, mode_t mode)
                return -1;
        }
 
-       ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode);
-       if (ofd == -1) {
+       if ((ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode)) < 0
+        && (!create_bak_dir || errno != ENOENT || make_bak_dir(dest) < 0
+         || (ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode)) < 0)) {
                rsyserr(FERROR, errno, "open %s", full_fname(dest));
                close(ifd);
                return -1;
@@ -406,7 +407,7 @@ int robust_rename(const char *from, const char *to, const char *partialptr,
                                        return -1;
                                to = partialptr;
                        }
-                       if (copy_file(from, to, mode) != 0)
+                       if (copy_file(from, to, mode, 0) != 0)
                                return -2;
                        do_unlink(from);
                        return 1;
@@ -1478,7 +1479,7 @@ void *expand_item_list(item_list *lp, size_t item_size,
                void *new_ptr;
                size_t new_size = lp->malloced;
                if (incr < 0)
-                       new_size -= incr; /* increase slowly */
+                       new_size += -incr; /* increase slowly */
                else if (new_size < (size_t)incr)
                        new_size += incr;
                else