Hello,

Jim Meyering wrote:
> Ondřej Vašík <[email protected]> wrote:
> > Jim Meyering wrote:
> >> Ondřej Vašík <[email protected]> wrote:
> >> > What about to split that into two patches? One for SELinux changes and
> >> > one for xattr changes (commited after 7.1) - to make it more safe - and
> >> > to give other distros more time to fix the leak...
> >> 
> >> That sounds even better.  I see that debian stable's libattr1-dev
> >> is at 1:2.4.43-2, which means it has the leak.
> >> Please do.
> >
> > Ok, split patches attached.
> 
> Thanks!  Looking at them now.
> 
> > Note: in the xattr patch there is no NEWS at the moment as it would
> > cause conflict when added after 7.1 release - I guess something like
> > "cp: -a option tries to preserve xattrs but doesn't inform about
> > failure" would be ok.

I guess it's time to add the amended cp-a-xattr patch... attached

Greetings,
         Ondrej
From f28d49d3315d6e57ce9654a05d3831335d3efc72 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <[email protected]>
Date: Wed, 11 Mar 2009 16:08:20 +0100
Subject: [PATCH] cp: make -a option preserve xattrs with reduced diagnostics

* copy.c (copy_attr_by_fd): Reduce xattr diagnostics for 'cp -a'.
  (copy_attr_by_name): Likewise.
* cp.c (main):  preserve xattrs with -a option, when possible
* doc/coreutils.texi: document that xattrs are preserved with
  cp -a, with no added diagnostics
* NEWS : mention that change
* tests/misc/xattr: Add tests for 'cp --preserve=all' and 'cp -a'.
---
 NEWS               |    3 +++
 doc/coreutils.texi |    7 +++----
 src/copy.c         |   22 +++++++++++++---------
 src/cp.c           |    1 +
 tests/misc/xattr   |   15 +++++++++++++--
 5 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/NEWS b/NEWS
index 9ace313..3d06ae0 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   at a time.  This was seen to increase throughput.  Up to 2 times
   when reading cached files on linux for example.
 
+  cp -a now tries to preserve extended attributes (xattr), doesn't inform
+  about failure, unlike with --preserve=all
+
 * Noteworthy changes in release 7.1 (2009-02-21) [stable]
 
 ** New features
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 2c1fae5..0bf978a 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -7262,10 +7262,9 @@ Preserve as much as possible of the structure and attributes of the
 original files in the copy (but do not attempt to preserve internal
 directory structure; i.e., @samp{ls -U} may list the entries in a copied
 directory in a different order).
-Try to preserve SELinux security context, but ignore any failure to do that
-and print no corresponding diagnostic.
-This option does not preserve extended attributes(xattr) at the moment.
-Equivalent to @option{-dR --preserve=all} with a few exceptions.
+Try to preserve SELinux security context and extended attributes (xattr),
+but ignore any failure to do that and print no corresponding diagnostic.
+Equivalent to @option{-dR --preserve=all} with the reduced diagnostics.
 
 @item -b
 @itemx @w...@kbd{--backup}[=@var{method}]}
diff --git a/src/copy.c b/src/copy.c
index e37fead..7b4dc08 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -153,13 +153,13 @@ copy_attr_quote (struct error_context *ctx ATTRIBUTE_UNUSED, char const *str)
 
 static void
 copy_attr_free (struct error_context *ctx ATTRIBUTE_UNUSED,
-		char const *str ATTRIBUTE_UNUSED)
+                char const *str ATTRIBUTE_UNUSED)
 {
 }
 
 static bool
 copy_attr_by_fd (char const *src_path, int src_fd,
-		 char const *dst_path, int dst_fd)
+                 char const *dst_path, int dst_fd, const struct cp_options *x)
 {
   struct error_context ctx =
   {
@@ -167,11 +167,13 @@ copy_attr_by_fd (char const *src_path, int src_fd,
     .quote = copy_attr_quote,
     .quote_free = copy_attr_free
   };
-  return 0 == attr_copy_fd (src_path, src_fd, dst_path, dst_fd, 0, &ctx);
+  return 0 == attr_copy_fd (src_path, src_fd, dst_path, dst_fd, 0,
+                            x->reduce_diagnostics ? NULL : &ctx);
 }
 
 static bool
-copy_attr_by_name (char const *src_path, char const *dst_path)
+copy_attr_by_name (char const *src_path, char const *dst_path,
+                   const struct cp_options *x)
 {
   struct error_context ctx =
   {
@@ -179,19 +181,21 @@ copy_attr_by_name (char const *src_path, char const *dst_path)
     .quote = copy_attr_quote,
     .quote_free = copy_attr_free
   };
-  return 0 == attr_copy_file (src_path, dst_path, 0, &ctx);
+  return 0 == attr_copy_file (src_path, dst_path, 0,
+                              x-> reduce_diagnostics ? NULL :&ctx);
 }
 #else /* USE_XATTR */
 
 static bool
 copy_attr_by_fd (char const *src_path, int src_fd,
-		 char const *dst_path, int dst_fd)
+                 char const *dst_path, int dst_fd, const struct cp_options *x)
 {
   return true;
 }
 
 static bool
-copy_attr_by_name (char const *src_path, char const *dst_path)
+copy_attr_by_name (char const *src_path, char const *dst_path,
+                   const struct cp_options *x)
 {
   return true;
 }
@@ -759,7 +763,7 @@ copy_reg (char const *src_name, char const *dst_name,
   set_author (dst_name, dest_desc, src_sb);
 
   if (x->preserve_xattr && ! copy_attr_by_fd (src_name, source_desc,
-					      dst_name, dest_desc)
+					      dst_name, dest_desc, x)
       && x->require_preserve_xattr)
     return false;
 
@@ -2076,7 +2080,7 @@ copy_internal (char const *src_name, char const *dst_name,
 
   set_author (dst_name, -1, &src_sb);
 
-  if (x->preserve_xattr && ! copy_attr_by_name (src_name, dst_name)
+  if (x->preserve_xattr && ! copy_attr_by_name (src_name, dst_name, x)
       && x->require_preserve_xattr)
     return false;
 
diff --git a/src/cp.c b/src/cp.c
index af4bd60..8785076 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -925,6 +925,7 @@ main (int argc, char **argv)
 	  x.require_preserve = true;
 	  if (selinux_enabled)
 	     x.preserve_security_context = true;
+	  x.preserve_xattr = true;
 	  x.reduce_diagnostics = true;
 	  x.recursive = true;
 	  break;
diff --git a/tests/misc/xattr b/tests/misc/xattr
index 4137c53..f067ff5 100755
--- a/tests/misc/xattr
+++ b/tests/misc/xattr
@@ -1,6 +1,7 @@
 #!/bin/sh
-# Ensure that cp --preserve=xattr and mv preserve extended attributes and
-# install does not preserve extended attributes.
+# Ensure that cp --preserve=xattr, cp --preserve=all and mv preserve extended
+# attributes and install does not preserve extended attributes.
+# cp -a should preserve xattr, error diagnostics should not be displayed
 
 # Copyright (C) 2009 Free Software Foundation, Inc.
 
@@ -66,6 +67,16 @@ cp --preserve=xattr a b || fail=1
 getfattr -d b >out_b || skip_test_ "failed to get xattr of file"
 grep -F "$xattr_pair" out_b >/dev/null || fail=1
 
+#test if --preserve=all option works
+cp --preserve=all a c || fail=1
+getfattr -d c >out_c || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_c >/dev/null || fail=1
+
+#test if -a option works without any diagnostics
+cp -a a d 2>err && test -s err && fail=1
+getfattr -d d >out_d || skip_test_ "failed to get xattr of file"
+grep -F "$xattr_pair" out_d >/dev/null || fail=1
+
 rm b || framework_failure
 
 # install should never preserve xattr
-- 
1.5.6.1.156.ge903b

Attachment: signature.asc
Description: Toto je digitálně podepsaná část zprávy

_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to