mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
cp: add support for --attributes-only.
This commit is contained in:
parent
ea43608ab8
commit
48ae9b64ba
1 changed files with 16 additions and 6 deletions
22
src/cp/cp.rs
22
src/cp/cp.rs
|
@ -157,6 +157,7 @@ pub enum CopyMode {
|
||||||
Sparse,
|
Sparse,
|
||||||
Copy,
|
Copy,
|
||||||
Update,
|
Update,
|
||||||
|
AttrOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -343,6 +344,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("WHEN")
|
.value_name("WHEN")
|
||||||
.help("control clone/CoW copies. See below"))
|
.help("control clone/CoW copies. See below"))
|
||||||
|
.arg(Arg::with_name(OPT_ATTRIBUTES_ONLY)
|
||||||
|
.long(OPT_ATTRIBUTES_ONLY)
|
||||||
|
.conflicts_with(OPT_COPY_CONTENTS)
|
||||||
|
.overrides_with(OPT_REFLINK)
|
||||||
|
.help("Don't copy the file data, just the attributes"))
|
||||||
|
|
||||||
// TODO: implement the following args
|
// TODO: implement the following args
|
||||||
.arg(Arg::with_name(OPT_ARCHIVE)
|
.arg(Arg::with_name(OPT_ARCHIVE)
|
||||||
|
@ -350,11 +356,6 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
.long(OPT_ARCHIVE)
|
.long(OPT_ARCHIVE)
|
||||||
.conflicts_with_all(&[OPT_PRESERVE_DEFUALT_ATTRIBUTES, OPT_PRESERVE, OPT_NO_PRESERVE])
|
.conflicts_with_all(&[OPT_PRESERVE_DEFUALT_ATTRIBUTES, OPT_PRESERVE, OPT_NO_PRESERVE])
|
||||||
.help("NotImplemented: same as -dR --preserve=all"))
|
.help("NotImplemented: same as -dR --preserve=all"))
|
||||||
.arg(Arg::with_name(OPT_ATTRIBUTES_ONLY)
|
|
||||||
.long(OPT_ATTRIBUTES_ONLY)
|
|
||||||
.conflicts_with(OPT_COPY_CONTENTS)
|
|
||||||
.overrides_with(OPT_REFLINK)
|
|
||||||
.help("NotImplemented: don't copy the file data, just the attributes"))
|
|
||||||
.arg(Arg::with_name(OPT_COPY_CONTENTS)
|
.arg(Arg::with_name(OPT_COPY_CONTENTS)
|
||||||
.long(OPT_COPY_CONTENTS)
|
.long(OPT_COPY_CONTENTS)
|
||||||
.conflicts_with(OPT_ATTRIBUTES_ONLY)
|
.conflicts_with(OPT_ATTRIBUTES_ONLY)
|
||||||
|
@ -481,6 +482,8 @@ impl CopyMode {
|
||||||
CopyMode::Sparse
|
CopyMode::Sparse
|
||||||
} else if matches.is_present(OPT_UPDATE) {
|
} else if matches.is_present(OPT_UPDATE) {
|
||||||
CopyMode::Update
|
CopyMode::Update
|
||||||
|
} else if matches.is_present(OPT_ATTRIBUTES_ONLY) {
|
||||||
|
CopyMode::AttrOnly
|
||||||
} else {
|
} else {
|
||||||
CopyMode::Copy
|
CopyMode::Copy
|
||||||
}
|
}
|
||||||
|
@ -508,7 +511,6 @@ impl Options {
|
||||||
fn from_matches(matches: &ArgMatches) -> CopyResult<Options> {
|
fn from_matches(matches: &ArgMatches) -> CopyResult<Options> {
|
||||||
let not_implemented_opts = vec![
|
let not_implemented_opts = vec![
|
||||||
OPT_ARCHIVE,
|
OPT_ARCHIVE,
|
||||||
OPT_ATTRIBUTES_ONLY,
|
|
||||||
OPT_COPY_CONTENTS,
|
OPT_COPY_CONTENTS,
|
||||||
OPT_NO_DEREFERENCE_PRESERVE_LINKS,
|
OPT_NO_DEREFERENCE_PRESERVE_LINKS,
|
||||||
OPT_DEREFERENCE,
|
OPT_DEREFERENCE,
|
||||||
|
@ -888,6 +890,14 @@ fn copy_file(source: &Path, dest: &Path, options: &Options) -> CopyResult<()> {
|
||||||
} else {
|
} else {
|
||||||
copy_helper(source, dest, options)?;
|
copy_helper(source, dest, options)?;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
CopyMode::AttrOnly => {
|
||||||
|
let dst_file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.truncate(false)
|
||||||
|
.create(true)
|
||||||
|
.open(dest)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue