Update utouch command to match latest uu_touch
This commit is contained in:
parent
21c331ad83
commit
aa95e6bdc8
68
Cargo.lock
generated
68
Cargo.lock
generated
|
@ -6377,7 +6377,7 @@ dependencies = [
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"libc",
|
"libc",
|
||||||
"quick-error 2.0.1",
|
"quick-error 2.0.1",
|
||||||
"uucore 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uucore 0.0.26",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"xattr",
|
"xattr",
|
||||||
]
|
]
|
||||||
|
@ -6389,7 +6389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "040aa4584036b2f65e05387b0ea9ac468afce1db325743ce5f350689fd9ce4ae"
|
checksum = "040aa4584036b2f65e05387b0ea9ac468afce1db325743ce5f350689fd9ce4ae"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"uucore 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uucore 0.0.26",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6401,7 +6401,7 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"rand",
|
"rand",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"uucore 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uucore 0.0.26",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6413,18 +6413,19 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"fs_extra",
|
"fs_extra",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"uucore 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uucore 0.0.26",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu_touch"
|
name = "uu_touch"
|
||||||
version = "0.0.26"
|
version = "0.0.27"
|
||||||
|
source = "git+https://github.com/uutils/coreutils.git#c90b69398f708b4ab3b70c7497995f05f0ff1290"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"filetime",
|
"filetime",
|
||||||
"parse_datetime",
|
"parse_datetime",
|
||||||
"uucore 0.0.26",
|
"uucore 0.0.27",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -6436,7 +6437,7 @@ checksum = "5951832d73199636bde6c0d61cf960932b3c4450142c290375bc10c7abed6db5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"platform-info",
|
"platform-info",
|
||||||
"uucore 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uucore 0.0.26",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6447,7 +6448,7 @@ checksum = "e3b44166eb6335aeac42744ea368cc4c32d3f2287a4ff765a5ce44d927ab8bb4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"libc",
|
"libc",
|
||||||
"uucore 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uucore 0.0.26",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -6463,21 +6464,6 @@ dependencies = [
|
||||||
"nix",
|
"nix",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"os_display",
|
"os_display",
|
||||||
"uucore_procs 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wild",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "uucore"
|
|
||||||
version = "0.0.26"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"glob",
|
|
||||||
"libc",
|
|
||||||
"nix",
|
|
||||||
"number_prefix",
|
|
||||||
"once_cell",
|
|
||||||
"os_display",
|
|
||||||
"uucore_procs 0.0.26",
|
"uucore_procs 0.0.26",
|
||||||
"wild",
|
"wild",
|
||||||
]
|
]
|
||||||
|
@ -6496,7 +6482,7 @@ dependencies = [
|
||||||
"number_prefix",
|
"number_prefix",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"os_display",
|
"os_display",
|
||||||
"uucore_procs 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uucore_procs 0.0.26",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"wild",
|
"wild",
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
|
@ -6505,12 +6491,19 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uucore_procs"
|
name = "uucore"
|
||||||
version = "0.0.26"
|
version = "0.0.27"
|
||||||
|
source = "git+https://github.com/uutils/coreutils.git#c90b69398f708b4ab3b70c7497995f05f0ff1290"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"clap",
|
||||||
"quote",
|
"glob",
|
||||||
"uuhelp_parser 0.0.26",
|
"libc",
|
||||||
|
"nix",
|
||||||
|
"number_prefix",
|
||||||
|
"once_cell",
|
||||||
|
"os_display",
|
||||||
|
"uucore_procs 0.0.27",
|
||||||
|
"wild",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6521,12 +6514,18 @@ checksum = "1a233a488da42f3ddb0aaa8a9f75a969e3f37e4de7e909d2d23f6aa3ee401d20"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"uuhelp_parser 0.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"uuhelp_parser 0.0.26",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuhelp_parser"
|
name = "uucore_procs"
|
||||||
version = "0.0.26"
|
version = "0.0.27"
|
||||||
|
source = "git+https://github.com/uutils/coreutils.git#c90b69398f708b4ab3b70c7497995f05f0ff1290"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"uuhelp_parser 0.0.27",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuhelp_parser"
|
name = "uuhelp_parser"
|
||||||
|
@ -6534,6 +6533,11 @@ version = "0.0.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "425a23c7b7145bc7620c9c445817c37b1f78b6790aee9f208133f3c028975b60"
|
checksum = "425a23c7b7145bc7620c9c445817c37b1f78b6790aee9f208133f3c028975b60"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uuhelp_parser"
|
||||||
|
version = "0.0.27"
|
||||||
|
source = "git+https://github.com/uutils/coreutils.git#c90b69398f708b4ab3b70c7497995f05f0ff1290"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
|
|
|
@ -163,7 +163,7 @@ uu_cp = "0.0.25"
|
||||||
uu_mkdir = "0.0.25"
|
uu_mkdir = "0.0.25"
|
||||||
uu_mktemp = "0.0.25"
|
uu_mktemp = "0.0.25"
|
||||||
uu_mv = "0.0.25"
|
uu_mv = "0.0.25"
|
||||||
uu_touch = { path = "../coreutils/src/uu/touch" }
|
uu_touch = { git = "https://github.com/uutils/coreutils.git" }
|
||||||
uu_whoami = "0.0.25"
|
uu_whoami = "0.0.25"
|
||||||
uu_uname = "0.0.25"
|
uu_uname = "0.0.25"
|
||||||
uucore = "0.0.25"
|
uucore = "0.0.25"
|
||||||
|
|
|
@ -5,14 +5,17 @@ use chrono::{DateTime, FixedOffset};
|
||||||
use filetime::FileTime;
|
use filetime::FileTime;
|
||||||
|
|
||||||
use nu_engine::CallExt;
|
use nu_engine::CallExt;
|
||||||
|
use nu_path::expand_path_with;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type,
|
Category, Example, NuGlob, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type,
|
||||||
};
|
};
|
||||||
use uu_touch::error::TouchError;
|
use uu_touch::error::TouchError;
|
||||||
use uu_touch::{ChangeTimes, InputFile, Options, Source};
|
use uu_touch::{ChangeTimes, InputFile, Options, Source};
|
||||||
|
|
||||||
|
use super::util::get_rest_for_glob_pattern;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct UTouch;
|
pub struct UTouch;
|
||||||
|
|
||||||
|
@ -28,21 +31,21 @@ impl Command for UTouch {
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("utouch")
|
Signature::build("utouch")
|
||||||
.input_output_types(vec![ (Type::Nothing, Type::Nothing) ])
|
.input_output_types(vec![ (Type::Nothing, Type::Nothing) ])
|
||||||
.required(
|
.rest(
|
||||||
"filename",
|
"files",
|
||||||
SyntaxShape::Filepath,
|
SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::Filepath]),
|
||||||
"The path of the file you want to create.",
|
"The file(s) to create."
|
||||||
)
|
)
|
||||||
.named(
|
.named(
|
||||||
"reference",
|
"reference",
|
||||||
SyntaxShape::Filepath,
|
SyntaxShape::Filepath,
|
||||||
"change the file or directory time to the time of the reference file/directory",
|
"use the access and modification times of the reference file/directory instead of the current time",
|
||||||
Some('r'),
|
Some('r'),
|
||||||
)
|
)
|
||||||
.named(
|
.named(
|
||||||
"timestamp",
|
"timestamp",
|
||||||
SyntaxShape::DateTime,
|
SyntaxShape::DateTime,
|
||||||
"use the given time instead of the current time",
|
"use the given timestamp instead of the current time",
|
||||||
Some('t')
|
Some('t')
|
||||||
)
|
)
|
||||||
.named(
|
.named(
|
||||||
|
@ -53,12 +56,12 @@ impl Command for UTouch {
|
||||||
)
|
)
|
||||||
.switch(
|
.switch(
|
||||||
"modified",
|
"modified",
|
||||||
"change the modification time of the file or directory. If no timestamp, date or reference file/directory is given, the current time is used",
|
"change only the modification time (if used with -a, access time is changed too)",
|
||||||
Some('m'),
|
Some('m'),
|
||||||
)
|
)
|
||||||
.switch(
|
.switch(
|
||||||
"access",
|
"access",
|
||||||
"change the access time of the file or directory. If no timestamp, date or reference file/directory is given, the current time is used",
|
"change only the access time (if used with -m, modification time is changed too)",
|
||||||
Some('a'),
|
Some('a'),
|
||||||
)
|
)
|
||||||
.switch(
|
.switch(
|
||||||
|
@ -90,8 +93,16 @@ impl Command for UTouch {
|
||||||
let change_atime: bool = call.has_flag(engine_state, stack, "access")?;
|
let change_atime: bool = call.has_flag(engine_state, stack, "access")?;
|
||||||
let no_create: bool = call.has_flag(engine_state, stack, "no-create")?;
|
let no_create: bool = call.has_flag(engine_state, stack, "no-create")?;
|
||||||
let no_deref: bool = call.has_flag(engine_state, stack, "no-dereference")?;
|
let no_deref: bool = call.has_flag(engine_state, stack, "no-dereference")?;
|
||||||
let target: Spanned<String> = call.req(engine_state, stack, 0)?;
|
let file_globs: Vec<Spanned<NuGlob>> =
|
||||||
let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 1)?;
|
get_rest_for_glob_pattern(engine_state, stack, call, 0)?;
|
||||||
|
let cwd = engine_state.cwd(Some(stack))?;
|
||||||
|
|
||||||
|
if file_globs.is_empty() {
|
||||||
|
return Err(ShellError::MissingParameter {
|
||||||
|
param_name: "requires file paths".to_string(),
|
||||||
|
span: call.head,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let (reference_file, reference_span) = if let Some(reference) =
|
let (reference_file, reference_span) = if let Some(reference) =
|
||||||
call.get_flag::<Spanned<PathBuf>>(engine_state, stack, "reference")?
|
call.get_flag::<Spanned<PathBuf>>(engine_state, stack, "reference")?
|
||||||
|
@ -144,15 +155,14 @@ impl Command for UTouch {
|
||||||
ChangeTimes::Both
|
ChangeTimes::Both
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut files = vec![InputFile::Path(PathBuf::from(target.item))];
|
let mut input_files = Vec::new();
|
||||||
let mut file_spans = vec![target.span];
|
for file_glob in &file_globs {
|
||||||
for file in rest {
|
let path = expand_path_with(file_glob.item.as_ref(), &cwd, file_glob.item.is_expand());
|
||||||
files.push(InputFile::Path(PathBuf::from(file.item)));
|
input_files.push(InputFile::Path(path));
|
||||||
file_spans.push(file.span);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = uu_touch::touch(
|
if let Err(err) = uu_touch::touch(
|
||||||
&files,
|
&input_files,
|
||||||
&Options {
|
&Options {
|
||||||
no_create,
|
no_create,
|
||||||
no_deref,
|
no_deref,
|
||||||
|
@ -163,13 +173,21 @@ impl Command for UTouch {
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
let nu_err = match err {
|
let nu_err = match err {
|
||||||
|
TouchError::TouchFileError { path, index, error } => ShellError::GenericError {
|
||||||
|
error: format!("Could not touch {}", path.display()),
|
||||||
|
msg: error.to_string(),
|
||||||
|
span: Some(file_globs[index].span),
|
||||||
|
help: None,
|
||||||
|
inner: Vec::new(),
|
||||||
|
},
|
||||||
TouchError::InvalidDateFormat(date) => ShellError::IncorrectValue {
|
TouchError::InvalidDateFormat(date) => ShellError::IncorrectValue {
|
||||||
msg: format!("Invalid date: {}", date),
|
msg: format!("Invalid date: {}", date),
|
||||||
val_span: date_span.expect("utouch was given a date"),
|
val_span: date_span.expect("utouch should've been given a date"),
|
||||||
call_span: call.head,
|
call_span: call.head,
|
||||||
},
|
},
|
||||||
TouchError::ReferenceFileInaccessible(reference_path, io_err) => {
|
TouchError::ReferenceFileInaccessible(reference_path, io_err) => {
|
||||||
let span = reference_span.expect("utouch was given a reference file");
|
let span =
|
||||||
|
reference_span.expect("utouch should've been given a reference file");
|
||||||
if io_err.kind() == ErrorKind::NotFound {
|
if io_err.kind() == ErrorKind::NotFound {
|
||||||
// todo merge main into this to say which file not found
|
// todo merge main into this to say which file not found
|
||||||
ShellError::FileNotFound {
|
ShellError::FileNotFound {
|
||||||
|
@ -177,11 +195,13 @@ impl Command for UTouch {
|
||||||
file: reference_path.display().to_string(),
|
file: reference_path.display().to_string(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
io_to_nu_err(
|
ShellError::GenericError {
|
||||||
io_err,
|
error: io_err.to_string(),
|
||||||
format!("Failed to read metadata of {}", reference_path.display()),
|
msg: format!("Failed to read metadata of {}", reference_path.display()),
|
||||||
span,
|
span: Some(span),
|
||||||
)
|
help: None,
|
||||||
|
inner: Vec::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => ShellError::GenericError {
|
_ => ShellError::GenericError {
|
||||||
|
@ -233,13 +253,3 @@ impl Command for UTouch {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn io_to_nu_err(err: std::io::Error, msg: String, span: Span) -> ShellError {
|
|
||||||
ShellError::GenericError {
|
|
||||||
error: err.to_string(),
|
|
||||||
msg,
|
|
||||||
span: Some(span),
|
|
||||||
help: None,
|
|
||||||
inner: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user