Skip to content

Commit

Permalink
cp: make cp -a not fail on Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jfinkels committed Oct 10, 2022
1 parent 38cbada commit 7868e41
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,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.
}
}
};
Expand Down

0 comments on commit 7868e41

Please sign in to comment.