cp: make cp -a not fail on Windows

Before this commit, `cp -a` would terminate with a non-zero status
code on Windows because there are no extended attributes (xattr) to
copy. However, the GNU documentation for cp states

> Try to preserve SELinux security context and extended attributes
> (xattr), but ignore any failure to do that and print no
> corresponding diagnostic.

so it seems reasonable to do nothing instead of exiting with an error
in this case.
This commit is contained in:
Jeffrey Finkelstein 2022-10-10 12:07:17 -04:00
parent cee6c25cc4
commit cd3f7b89a7

View file

@ -1146,7 +1146,16 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu
}
#[cfg(not(unix))]
{
return Err("XAttrs are only supported on unix.".to_string().into());
// The documentation for GNU cp states:
//
// > Try to preserve SELinux security context and
// > extended attributes (xattr), but ignore any failure
// > to do that and print no corresponding diagnostic.
//
// so we simply do nothing here.
//
// TODO Silently ignore failures in the `#[cfg(unix)]`
// block instead of terminating immediately on errors.
}
}
};