xattr-hlink.diff 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --- a/hlink.c
  2. +++ b/hlink.c
  3. @@ -30,6 +30,7 @@ extern int inc_recurse;
  4. extern int do_xfers;
  5. extern int link_dest;
  6. extern int preserve_acls;
  7. +extern int preserve_xattrs;
  8. extern int make_backups;
  9. extern int protocol_version;
  10. extern int remove_source_files;
  11. @@ -368,6 +369,9 @@ int hard_link_check(struct file_struct *file, int ndx, const char *fname,
  12. #ifdef SUPPORT_ACLS
  13. alt_sx.acc_acl = alt_sx.def_acl = NULL;
  14. #endif
  15. +#ifdef SUPPORT_XATTRS
  16. + alt_sx.xattr = NULL;
  17. +#endif
  18. do {
  19. pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
  20. if (link_stat(cmpbuf, &alt_sx.st, 0) < 0)
  21. @@ -396,19 +400,37 @@ int hard_link_check(struct file_struct *file, int ndx, const char *fname,
  22. sxp->st = alt_sx.st;
  23. #ifdef SUPPORT_ACLS
  24. if (preserve_acls && !S_ISLNK(file->mode)) {
  25. - if (!ACL_READY(*sxp))
  26. + free_acl(sxp);
  27. + if (!ACL_READY(alt_sx))
  28. get_acl(cmpbuf, sxp);
  29. else {
  30. sxp->acc_acl = alt_sx.acc_acl;
  31. sxp->def_acl = alt_sx.def_acl;
  32. + alt_sx.acc_acl = alt_sx.def_acl = NULL;
  33. }
  34. }
  35. #endif
  36. - }
  37. +#ifdef SUPPORT_XATTRS
  38. + if (preserve_xattrs) {
  39. + free_xattr(sxp);
  40. + if (!XATTR_READY(alt_sx))
  41. + get_xattr(cmpbuf, sxp);
  42. + else {
  43. + sxp->xattr = alt_sx.xattr;
  44. + alt_sx.xattr = NULL;
  45. + }
  46. + }
  47. +#endif
  48. + } else {
  49. #ifdef SUPPORT_ACLS
  50. - else if (preserve_acls)
  51. - free_acl(&alt_sx);
  52. + if (preserve_acls)
  53. + free_acl(&alt_sx);
  54. +#endif
  55. +#ifdef SUPPORT_XATTRS
  56. + if (preserve_xattrs)
  57. + free_xattr(&alt_sx);
  58. #endif
  59. + }
  60. }
  61. if (maybe_hard_link(file, ndx, fname, statret, sxp, prev_name, &prev_st,
  62. @@ -475,6 +497,9 @@ void finish_hard_link(struct file_struct *file, const char *fname, int fin_ndx,
  63. #ifdef SUPPORT_ACLS
  64. prev_sx.acc_acl = prev_sx.def_acl = NULL;
  65. #endif
  66. +#ifdef SUPPORT_XATTRS
  67. + prev_sx.xattr = NULL;
  68. +#endif
  69. while ((ndx = prev_ndx) >= 0) {
  70. int val;
  71. @@ -491,6 +516,10 @@ void finish_hard_link(struct file_struct *file, const char *fname, int fin_ndx,
  72. if (preserve_acls)
  73. free_acl(&prev_sx);
  74. #endif
  75. +#ifdef SUPPORT_XATTRS
  76. + if (preserve_xattrs)
  77. + free_xattr(&prev_sx);
  78. +#endif
  79. if (val < 0)
  80. continue;
  81. if (remove_source_files == 1 && do_xfers)