mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Merge branch 'main' into fix_docs
This commit is contained in:
commit
5ade45f8e9
3 changed files with 43 additions and 8 deletions
|
@ -1193,7 +1193,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
|
||||||
for source in sources {
|
for source in sources {
|
||||||
if seen_sources.contains(source) {
|
if seen_sources.contains(source) {
|
||||||
// FIXME: compare sources by the actual file they point to, not their path. (e.g. dir/file == dir/../dir/file in most cases)
|
// FIXME: compare sources by the actual file they point to, not their path. (e.g. dir/file == dir/../dir/file in most cases)
|
||||||
show_warning!("source {} specified more than once", source.quote());
|
show_warning!("source file {} specified more than once", source.quote());
|
||||||
} else {
|
} else {
|
||||||
let dest = construct_dest_path(source, target, target_type, options)
|
let dest = construct_dest_path(source, target, target_type, options)
|
||||||
.unwrap_or_else(|_| target.to_path_buf());
|
.unwrap_or_else(|_| target.to_path_buf());
|
||||||
|
|
|
@ -2414,6 +2414,11 @@ fn display_items(
|
||||||
// Display the SELinux security context or '?' if none is found. When used with the `-l`
|
// Display the SELinux security context or '?' if none is found. When used with the `-l`
|
||||||
// option, print the security context to the left of the size column.
|
// option, print the security context to the left of the size column.
|
||||||
|
|
||||||
|
let quoted = items.iter().any(|item| {
|
||||||
|
let name = escape_name(&item.display_name, &config.quoting_style);
|
||||||
|
name.starts_with('\'')
|
||||||
|
});
|
||||||
|
|
||||||
if config.format == Format::Long {
|
if config.format == Format::Long {
|
||||||
let padding_collection = calculate_padding_collection(items, config, out);
|
let padding_collection = calculate_padding_collection(items, config, out);
|
||||||
|
|
||||||
|
@ -2431,7 +2436,15 @@ fn display_items(
|
||||||
display_additional_leading_info(item, &padding_collection, config, out)?;
|
display_additional_leading_info(item, &padding_collection, config, out)?;
|
||||||
write!(out, "{more_info}")?;
|
write!(out, "{more_info}")?;
|
||||||
}
|
}
|
||||||
display_item_long(item, &padding_collection, config, out, dired, style_manager)?;
|
display_item_long(
|
||||||
|
item,
|
||||||
|
&padding_collection,
|
||||||
|
config,
|
||||||
|
out,
|
||||||
|
dired,
|
||||||
|
style_manager,
|
||||||
|
quoted,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut longest_context_len = 1;
|
let mut longest_context_len = 1;
|
||||||
|
@ -2448,7 +2461,6 @@ fn display_items(
|
||||||
let padding = calculate_padding_collection(items, config, out);
|
let padding = calculate_padding_collection(items, config, out);
|
||||||
|
|
||||||
let mut names_vec = Vec::new();
|
let mut names_vec = Vec::new();
|
||||||
|
|
||||||
for i in items {
|
for i in items {
|
||||||
let more_info = display_additional_leading_info(i, &padding, config, out)?;
|
let more_info = display_additional_leading_info(i, &padding, config, out)?;
|
||||||
let cell = display_item_name(i, config, prefix_context, more_info, out, style_manager);
|
let cell = display_item_name(i, config, prefix_context, more_info, out, style_manager);
|
||||||
|
@ -2458,8 +2470,12 @@ fn display_items(
|
||||||
let names = names_vec.into_iter();
|
let names = names_vec.into_iter();
|
||||||
|
|
||||||
match config.format {
|
match config.format {
|
||||||
Format::Columns => display_grid(names, config.width, Direction::TopToBottom, out)?,
|
Format::Columns => {
|
||||||
Format::Across => display_grid(names, config.width, Direction::LeftToRight, out)?,
|
display_grid(names, config.width, Direction::TopToBottom, out, quoted)?;
|
||||||
|
}
|
||||||
|
Format::Across => {
|
||||||
|
display_grid(names, config.width, Direction::LeftToRight, out, quoted)?;
|
||||||
|
}
|
||||||
Format::Commas => {
|
Format::Commas => {
|
||||||
let mut current_col = 0;
|
let mut current_col = 0;
|
||||||
let mut names = names;
|
let mut names = names;
|
||||||
|
@ -2524,6 +2540,7 @@ fn display_grid(
|
||||||
width: u16,
|
width: u16,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
out: &mut BufWriter<Stdout>,
|
out: &mut BufWriter<Stdout>,
|
||||||
|
quoted: bool,
|
||||||
) -> UResult<()> {
|
) -> UResult<()> {
|
||||||
if width == 0 {
|
if width == 0 {
|
||||||
// If the width is 0 we print one single line
|
// If the width is 0 we print one single line
|
||||||
|
@ -2545,7 +2562,15 @@ fn display_grid(
|
||||||
let mut grid = Grid::new(GridOptions { filling, direction });
|
let mut grid = Grid::new(GridOptions { filling, direction });
|
||||||
|
|
||||||
for name in names {
|
for name in names {
|
||||||
grid.add(name);
|
let formatted_name = Cell {
|
||||||
|
contents: if quoted && !name.contents.starts_with('\'') {
|
||||||
|
format!(" {}", name.contents)
|
||||||
|
} else {
|
||||||
|
name.contents
|
||||||
|
},
|
||||||
|
width: name.width,
|
||||||
|
};
|
||||||
|
grid.add(formatted_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
match grid.fit_into_width(width as usize) {
|
match grid.fit_into_width(width as usize) {
|
||||||
|
@ -2597,6 +2622,7 @@ fn display_item_long(
|
||||||
out: &mut BufWriter<Stdout>,
|
out: &mut BufWriter<Stdout>,
|
||||||
dired: &mut DiredOutput,
|
dired: &mut DiredOutput,
|
||||||
style_manager: &mut StyleManager,
|
style_manager: &mut StyleManager,
|
||||||
|
quoted: bool,
|
||||||
) -> UResult<()> {
|
) -> UResult<()> {
|
||||||
let mut output_display: String = String::new();
|
let mut output_display: String = String::new();
|
||||||
if config.dired {
|
if config.dired {
|
||||||
|
@ -2689,8 +2715,15 @@ fn display_item_long(
|
||||||
|
|
||||||
write!(output_display, " {} ", display_date(md, config)).unwrap();
|
write!(output_display, " {} ", display_date(md, config)).unwrap();
|
||||||
|
|
||||||
let displayed_item =
|
let item_name =
|
||||||
display_item_name(item, config, None, String::new(), out, style_manager).contents;
|
display_item_name(item, config, None, String::new(), out, style_manager).contents;
|
||||||
|
|
||||||
|
let displayed_item = if quoted && !item_name.starts_with('\'') {
|
||||||
|
format!(" {}", item_name)
|
||||||
|
} else {
|
||||||
|
item_name
|
||||||
|
};
|
||||||
|
|
||||||
if config.dired {
|
if config.dired {
|
||||||
let (start, end) = dired::calculate_dired(
|
let (start, end) = dired::calculate_dired(
|
||||||
&dired.dired_positions,
|
&dired.dired_positions,
|
||||||
|
|
|
@ -111,7 +111,9 @@ fn test_cp_duplicate_files() {
|
||||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||||
.arg(TEST_COPY_TO_FOLDER)
|
.arg(TEST_COPY_TO_FOLDER)
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stderr_contains("specified more than once");
|
.stderr_contains(format!(
|
||||||
|
"source file '{TEST_HELLO_WORLD_SOURCE}' specified more than once"
|
||||||
|
));
|
||||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue