Skip to content

Commit

Permalink
Added init_stat_x() to avoid duplication of acl/xattr init code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne Davison committed Jan 3, 2009
1 parent c43c661 commit 09ca0d1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 39 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 4 additions & 13 deletions backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "rsync.h"
#include "ifuncs.h"

extern int am_root;
extern int preserve_acls;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions flist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "rsync.h"
#include "inums.h"
#include "ifuncs.h"

extern int dry_run;
extern int do_xfers;
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 3 additions & 12 deletions hlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "rsync.h"
#include "inums.h"
#include "ifuncs.h"

extern int dry_run;
extern int list_only;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions ifuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 1 addition & 6 deletions rsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09ca0d1

Please sign in to comment.