1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

cp: Add support for preserving xattrs.

This commit is contained in:
Matt8898 2017-08-18 10:44:54 +02:00
parent 6d3e9eabe4
commit 4cb727f80b
2 changed files with 20 additions and 1 deletions

View file

@ -22,6 +22,9 @@ filetime = "0.1"
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
ioctl-sys = "0.5.2" ioctl-sys = "0.5.2"
[target.'cfg(unix)'.dependencies]
xattr="0.2.1"
[[bin]] [[bin]]
name = "cp" name = "cp"
path = "main.rs" path = "main.rs"

View file

@ -19,6 +19,8 @@ use filetime::FileTime;
#[macro_use] extern crate ioctl_sys; #[macro_use] extern crate ioctl_sys;
#[macro_use] extern crate uucore; #[macro_use] extern crate uucore;
#[macro_use] extern crate quick_error; #[macro_use] extern crate quick_error;
#[cfg(unix)]
extern crate xattr;
use std::mem; use std::mem;
use std::ffi::CString; use std::ffi::CString;
@ -796,7 +798,21 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu
}, },
Attribute::Context => return Err(Error::NotImplemented("preserving context not implemented".to_string())), Attribute::Context => return Err(Error::NotImplemented("preserving context not implemented".to_string())),
Attribute::Links => return Err(Error::NotImplemented("preserving links not implemented".to_string())), Attribute::Links => return Err(Error::NotImplemented("preserving links not implemented".to_string())),
Attribute::Xattr => return Err(Error::NotImplemented("preserving xattr not implemented".to_string())), Attribute::Xattr => {
#[cfg(unix)]
{
let xattrs = xattr::list(source)?;
for attr in xattrs {
if let Some(attr_value) = xattr::get(source, attr.clone())? {
xattr::set(dest, attr, &attr_value[..]);
}
}
}
#[cfg(not(unix))]
{
return Err(format!("XAttrs are only supported on unix.").into());
}
},
Attribute::All => return Err(Error::NotImplemented("preserving a not implemented".to_string())), Attribute::All => return Err(Error::NotImplemented("preserving a not implemented".to_string())),
}) })
} }