Added init_stat_x() to avoid duplication of acl/xattr init code.
authorWayne Davison <wayned@samba.org>
Sat, 3 Jan 2009 16:53:59 +0000 (08:53 -0800)
committerWayne Davison <wayned@samba.org>
Sat, 3 Jan 2009 16:53:59 +0000 (08:53 -0800)
NEWS
backup.c
flist.c
generator.c
hlink.c
ifuncs.h
rsync.c

diff --git a/NEWS b/NEWS
index f0de0ca..eaacde6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -51,3 +51,5 @@ Changes since 3.0.4:
 
     - The pool_alloc library has received some minor improvements in alignment
       handling.
+
+    - Added init_stat_x() function to avoid duplication of acl/xattr init code.
index 60c85b1..b40da92 100644 (file)
--- a/backup.c
+++ b/backup.c
@@ -19,6 +19,7 @@
  */
 
 #include "rsync.h"
+#include "ifuncs.h"
 
 extern int am_root;
 extern int preserve_acls;
@@ -131,17 +132,12 @@ int make_bak_dir(const char *fullpath)
                if (p >= rel) {
                        /* Try to transfer the directory settings of the
                         * actual dir that the files are coming from. */
+                       init_stat_x(&sx);
                        if (x_stat(rel, &sx.st, NULL) < 0) {
                                rsyserr(FERROR, errno,
                                        "make_bak_dir stat %s failed",
                                        full_fname(rel));
                        } else {
-#ifdef SUPPORT_ACLS
-                               sx.acc_acl = sx.def_acl = NULL;
-#endif
-#ifdef SUPPORT_XATTRS
-                               sx.xattr = NULL;
-#endif
                                if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
                                        continue;
 #ifdef SUPPORT_ACLS
@@ -207,15 +203,10 @@ static int keep_backup(const char *fname)
        int kept = 0;
        int ret_code;
 
-       /* return if no file to keep */
+       init_stat_x(&sx);
+       /* Return success if no file to keep. */
        if (x_lstat(fname, &sx.st, NULL) < 0)
                return 1;
-#ifdef SUPPORT_ACLS
-       sx.acc_acl = sx.def_acl = NULL;
-#endif
-#ifdef SUPPORT_XATTRS
-       sx.xattr = NULL;
-#endif
 
        if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
                return 1; /* the file could have disappeared */
diff --git a/flist.c b/flist.c
index e86b57a..84420c0 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -1378,6 +1378,7 @@ static struct file_struct *send_file_name(int f, struct file_list *flist,
 #endif
 #if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
                stat_x sx;
+               init_stat_x(&sx);
 #endif
 
 #ifdef SUPPORT_LINKS
@@ -1441,7 +1442,6 @@ static struct file_struct *send_file_name(int f, struct file_list *flist,
 #ifdef SUPPORT_ACLS
                if (preserve_acls && !S_ISLNK(file->mode)) {
                        sx.st.st_mode = file->mode;
-                       sx.acc_acl = sx.def_acl = NULL;
                        if (get_acl(fname, &sx) < 0) {
                                io_error |= IOERR_GENERAL;
                                return NULL;
@@ -1450,7 +1450,6 @@ static struct file_struct *send_file_name(int f, struct file_list *flist,
 #endif
 #ifdef SUPPORT_XATTRS
                if (preserve_xattrs) {
-                       sx.xattr = NULL;
                        if (get_xattr(fname, &sx) < 0) {
                                io_error |= IOERR_GENERAL;
                                return NULL;
index 1db0fe0..1e66085 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "rsync.h"
 #include "inums.h"
+#include "ifuncs.h"
 
 extern int dry_run;
 extern int do_xfers;
@@ -1333,12 +1334,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                }
        }
 
-#ifdef SUPPORT_ACLS
-       sx.acc_acl = sx.def_acl = NULL;
-#endif
-#ifdef SUPPORT_XATTRS
-       sx.xattr = NULL;
-#endif
+       init_stat_x(&sx);
        if (dry_run > 1 || (dry_missing_dir && is_below(file, dry_missing_dir))) {
          parent_is_dry_missing:
                if (fuzzy_dirlist) {
diff --git a/hlink.c b/hlink.c
index 0581398..e6ed072 100644 (file)
--- a/hlink.c
+++ b/hlink.c
@@ -22,6 +22,7 @@
 
 #include "rsync.h"
 #include "inums.h"
+#include "ifuncs.h"
 
 extern int dry_run;
 extern int list_only;
@@ -393,12 +394,7 @@ int hard_link_check(struct file_struct *file, int ndx, const char *fname,
                char cmpbuf[MAXPATHLEN];
                stat_x alt_sx;
                int j = 0;
-#ifdef SUPPORT_ACLS
-               alt_sx.acc_acl = alt_sx.def_acl = NULL;
-#endif
-#ifdef SUPPORT_XATTRS
-               alt_sx.xattr = NULL;
-#endif
+               init_stat_x(&alt_sx);
                do {
                        pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
                        if (link_stat(cmpbuf, &alt_sx.st, 0) < 0)
@@ -521,12 +517,7 @@ void finish_hard_link(struct file_struct *file, const char *fname, int fin_ndx,
        } else
                our_name = fname;
 
-#ifdef SUPPORT_ACLS
-       prev_sx.acc_acl = prev_sx.def_acl = NULL;
-#endif
-#ifdef SUPPORT_XATTRS
-       prev_sx.xattr = NULL;
-#endif
+       init_stat_x(&prev_sx);
 
        while ((ndx = prev_ndx) >= 0) {
                int val;
index 0fe900a..8c128d5 100644 (file)
--- a/ifuncs.h
+++ b/ifuncs.h
@@ -66,3 +66,14 @@ d_name(struct dirent *di)
        return di->d_name;
 #endif
 }
+
+static inline void
+init_stat_x(stat_x *sx_p)
+{
+#ifdef SUPPORT_ACLS
+       sx_p->acc_acl = sx_p->def_acl = NULL;
+#endif
+#ifdef SUPPORT_XATTRS
+       sx_p->xattr = NULL;
+#endif
+}
diff --git a/rsync.c b/rsync.c
index 845517d..49cc41c 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -395,12 +395,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
                                full_fname(fname));
                        return 0;
                }
-#ifdef SUPPORT_ACLS
-               sx2.acc_acl = sx2.def_acl = NULL;
-#endif
-#ifdef SUPPORT_XATTRS
-               sx2.xattr = NULL;
-#endif
+               init_stat_x(&sx2);
                sxp = &sx2;
                inherit = !preserve_perms;
        } else