mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-14 17:21:04 +00:00
cp: manages target with trailing '/'
This commit is contained in:
parent
cb27b9c9c3
commit
aabf5fa577
4 changed files with 40 additions and 4 deletions
|
|
@ -17,7 +17,9 @@ use std::path::{Path, PathBuf, StripPrefixError};
|
|||
use indicatif::ProgressBar;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::UIoError;
|
||||
use uucore::fs::{canonicalize, FileInformation, MissingHandling, ResolveMode};
|
||||
use uucore::fs::{
|
||||
canonicalize, path_ends_with_terminator, FileInformation, MissingHandling, ResolveMode,
|
||||
};
|
||||
use uucore::show;
|
||||
use uucore::show_error;
|
||||
use uucore::uio_error;
|
||||
|
|
@ -170,7 +172,14 @@ impl Entry {
|
|||
let mut descendant =
|
||||
get_local_to_root_parent(&source_absolute, context.root_parent.as_deref())?;
|
||||
if no_target_dir {
|
||||
descendant = descendant.strip_prefix(context.root)?.to_path_buf();
|
||||
let source_is_dir: bool = direntry.path().is_dir();
|
||||
if path_ends_with_terminator(context.target) && source_is_dir {
|
||||
if let Err(e) = std::fs::create_dir_all(context.target) {
|
||||
eprintln!("Failed to create directory: {}", e);
|
||||
}
|
||||
} else {
|
||||
descendant = descendant.strip_prefix(context.root)?.to_path_buf();
|
||||
}
|
||||
}
|
||||
|
||||
let local_to_target = context.target.join(descendant);
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ use platform::copy_on_write;
|
|||
use uucore::display::Quotable;
|
||||
use uucore::error::{set_exit_code, UClapError, UError, UResult, UUsageError};
|
||||
use uucore::fs::{
|
||||
are_hardlinks_to_same_file, canonicalize, is_symlink_loop, paths_refer_to_same_file,
|
||||
FileInformation, MissingHandling, ResolveMode,
|
||||
are_hardlinks_to_same_file, canonicalize, is_symlink_loop, path_ends_with_terminator,
|
||||
paths_refer_to_same_file, FileInformation, MissingHandling, ResolveMode,
|
||||
};
|
||||
use uucore::{backup_control, update_control};
|
||||
// These are exposed for projects (e.g. nushell) that want to create an `Options` value, which
|
||||
|
|
@ -1994,6 +1994,10 @@ fn copy_helper(
|
|||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
|
||||
if path_ends_with_terminator(dest) && !dest.is_dir() {
|
||||
return Err(Error::NotADirectory(dest.to_path_buf()));
|
||||
}
|
||||
|
||||
if source.as_os_str() == "/dev/null" {
|
||||
/* workaround a limitation of fs::copy
|
||||
* https://github.com/rust-lang/rust/issues/79390
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue