diff options
author | Wayne Davison <wayned@samba.org> | 2008-05-17 09:30:46 -0700 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2008-05-17 09:35:46 -0700 |
commit | e9489cd6cb380b30727bd3d074eacc59abca080e (patch) | |
tree | bc7f1cebf7a527b15326ad5af580e5407b403c3c /xattrs.c | |
parent | f1ca7c4429f2a8e9de72f91d95218bb324df6a9e (diff) | |
download | rsync-e9489cd6cb380b30727bd3d074eacc59abca080e.tar.gz |
Fixed several issues with preserving xattrs when using --backup.
Diffstat (limited to 'xattrs.c')
-rw-r--r-- | xattrs.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -288,6 +288,48 @@ int get_xattr(const char *fname, stat_x *sxp) return 0; } +int copy_xattrs(const char *source, const char *dest) +{ + ssize_t list_len, name_len; + size_t datum_len; + char *name, *ptr; +#ifdef HAVE_LINUX_XATTRS + int user_only = am_sender ? 0 : !am_root; +#endif + + /* This puts the name list into the "namebuf" buffer. */ + if ((list_len = get_xattr_names(source)) < 0) + return -1; + + for (name = namebuf; list_len > 0; name += name_len) { + name_len = strlen(name) + 1; + list_len -= name_len; + +#ifdef HAVE_LINUX_XATTRS + /* We always ignore the system namespace, and non-root + * ignores everything but the user namespace. */ + if (user_only ? !HAS_PREFIX(name, USER_PREFIX) + : HAS_PREFIX(name, SYSTEM_PREFIX)) + continue; +#endif + + datum_len = 0; + if (!(ptr = get_xattr_data(source, name, &datum_len, 0))) + return -1; + if (sys_lsetxattr(dest, name, ptr, datum_len) < 0) { + int save_errno = errno ? errno : EINVAL; + rsyserr(FERROR_XFER, errno, + "rsync_xal_set: lsetxattr(\"%s\",\"%s\") failed", + dest, name); + errno = save_errno; + return -1; + } + free(ptr); + } + + return 0; +} + static int find_matching_xattr(item_list *xalp) { size_t i, j; |