On 30.04.2015 17:30, Pádraig Brady wrote:
On 30/04/15 13:02, sa wrote:
it's still common today when you can copy files somewhere but subsequent
chown() on them returns EACCES:
NFS without strict uid/gid mapping,
CIFS with broken Unix Extensions - nowaday NAS devices,
less common filesystems like sshfs.
Maybe, but the `cp ... && rm` combo give more control
and isn't too awkward for this. Also it doesn't have
a functional disadvantage of using extra space, as
generally this is an issue between separate file systems.
I agree with these objections, but two orthogonal options
of doing almost the same thing cause frustration.
"Am I moving to remote share?" Then "is this one of those
"bad" shares?" (and if you don't know, you must guess).
Then, you type `cp ... && rm ...` or remember the name and options
of custom script. Then, after starting it, you remember that
SOURCE is on the same share and you must have used mv instead.
Also it has a functional advantage of being an atomic
operation, not deleting any files unless all were copied.
I agree, but I'm happy with standard and expected mv behaviour,
which is atomic move of each SOURCE argument.
Search for "mv: failed to preserve ownership" (with quotes) gives
an idea about diversity of failure cases.
Please consider the trivial patch attached. It passes existing tests.
I've tried to write a specific test, but couldn't find a safe way
to force mv copy files instead of rename within test framework.
--
sa
diff --git a/coreutils.orig/src/mv.c b/coreutils/src/mv.c
index 0bcc1bb..47463a2 100644
--- a/coreutils.orig/src/mv.c
+++ b/coreutils/src/mv.c
@@ -46,7 +46,8 @@
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
- STRIP_TRAILING_SLASHES_OPTION = CHAR_MAX + 1
+ STRIP_TRAILING_SLASHES_OPTION = CHAR_MAX + 1,
+ NO_PRESERVE_OWNERSHIP_OPTION = CHAR_MAX + 2
};
/* Remove any trailing slashes from each SOURCE argument. */
@@ -60,6 +61,7 @@ static struct option const long_options[] =
{"interactive", no_argument, NULL, 'i'},
{"no-clobber", no_argument, NULL, 'n'},
{"no-target-directory", no_argument, NULL, 'T'},
+ {"no-preserve-ownership", no_argument, NULL, NO_PRESERVE_OWNERSHIP_OPTION},
{"strip-trailing-slashes", no_argument, NULL, STRIP_TRAILING_SLASHES_OPTION},
{"suffix", required_argument, NULL, 'S'},
{"target-directory", required_argument, NULL, 't'},
@@ -317,6 +319,8 @@ If you specify more than one of -i, -f, -n, only the final one takes effect.\n\
-u, --update move only when the SOURCE file is newer\n\
than the destination file or when the\n\
destination file is missing\n\
+ --no-preserve-ownership do not copy ownership information\n\
+ when moving between file systems\n\
-v, --verbose explain what is being done\n\
-Z, --context set SELinux security context of destination\n\
file to default type\n\
@@ -432,6 +436,9 @@ main (int argc, char **argv)
x.set_security_context = true;
}
break;
+ case NO_PRESERVE_OWNERSHIP_OPTION:
+ x.preserve_ownership = false;
+ break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
default:
diff --git a/coreutils.orig/doc/coreutils.texi b/coreutils/doc/coreutils.texi
index 51d96b4..da67a9a 100644
--- a/coreutils.orig/doc/coreutils.texi
+++ b/coreutils/doc/coreutils.texi
@@ -8988,6 +8988,10 @@ directory succeeded, but the second didn't, the first would be left on
the destination partition and the second and third would be left on the
original partition.
+When moving between file systems, @command{mv} tries to copy ownership
+information like @code{cp -p}.
+This behaviour may be disabled by @option{--no-preserve-ownership} option.
+
@cindex extended attributes, xattr
@command{mv} always tries to copy extended attributes (xattr), which may
include SELinux context, ACLs or Capabilities.
@@ -9047,6 +9051,11 @@ Do not overwrite an existing file.
@mvOptsIfn
This option is mutually exclusive with @option{-b} or @option{--backup} option.
+@item --no-preserve-ownership
+@opindex --no-preserve-ownership
+@cindex ownership information, preserving
+When moving between file systems, do not copy ownership information.
+
@item -u
@itemx --update
@opindex -u