X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/1c3344a105f656a45f6b46e1710c3fc4ab862a9a..8e41b68e8f975c02a5d9281be780ba5d1a385107:/backup.c diff --git a/backup.c b/backup.c index 8cac4d51..05856aa2 100644 --- a/backup.c +++ b/backup.c @@ -5,8 +5,9 @@ * Copyright (C) 2003-2007 Wayne Davison * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,8 +15,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + * with this program; if not, visit the http://fsf.org website. */ #include "rsync.h" @@ -23,6 +23,7 @@ extern int verbose; extern int am_root; extern int preserve_acls; +extern int preserve_xattrs; extern int preserve_devices; extern int preserve_specials; extern int preserve_links; @@ -126,13 +127,16 @@ static int make_bak_dir(char *fullpath) if (p >= rel) { /* Try to transfer the directory settings of the * actual dir that the files are coming from. */ - if (do_stat(rel, &sx.st) < 0) { + 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; @@ -143,8 +147,15 @@ static int make_bak_dir(char *fullpath) free_acl(&sx); } #endif - set_file_attrs(fullpath, file, NULL, 0); - free(file); +#ifdef SUPPORT_XATTRS + if (preserve_xattrs) { + get_xattr(rel, &sx); + cache_xattr(file, &sx); + free_xattr(&sx); + } +#endif + set_file_attrs(fullpath, file, NULL, NULL, 0); + unmake_file(file); } } *p = '/'; @@ -189,11 +200,14 @@ static int keep_backup(const char *fname) int ret_code; /* return if no file to keep */ - if (do_lstat(fname, &sx.st) < 0) + 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 */ @@ -210,6 +224,13 @@ static int keep_backup(const char *fname) free_acl(&sx); } #endif +#ifdef SUPPORT_XATTRS + if (preserve_xattrs) { + get_xattr(fname, &sx); + cache_xattr(file, &sx); + free_xattr(&sx); + } +#endif /* Check to see if this is a device file, or link */ if ((am_root && preserve_devices && IS_DEVICE(file->mode)) @@ -288,7 +309,7 @@ static int keep_backup(const char *fname) robust_unlink(fname); /* Just in case... */ } } - set_file_attrs(buf, file, NULL, 0); + set_file_attrs(buf, file, NULL, fname, 0); unmake_file(file); if (verbose > 1) {