mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
du: show error for nul names with --files0-from
This commit is contained in:
parent
2a81c91f52
commit
239e5426e6
2 changed files with 38 additions and 4 deletions
|
@ -26,11 +26,11 @@ use std::sync::mpsc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
use uucore::display::{print_verbatim, Quotable};
|
use uucore::display::{print_verbatim, Quotable};
|
||||||
use uucore::error::{FromIo, UError, UResult, USimpleError};
|
use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError};
|
||||||
use uucore::line_ending::LineEnding;
|
use uucore::line_ending::LineEnding;
|
||||||
use uucore::parse_glob;
|
use uucore::parse_glob;
|
||||||
use uucore::parse_size::{parse_size_u64, ParseSizeError};
|
use uucore::parse_size::{parse_size_u64, ParseSizeError};
|
||||||
use uucore::{format_usage, help_about, help_section, help_usage, show, show_warning};
|
use uucore::{format_usage, help_about, help_section, help_usage, show, show_error, show_warning};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use windows_sys::Win32::Foundation::HANDLE;
|
use windows_sys::Win32::Foundation::HANDLE;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -621,9 +621,14 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
|
||||||
|
|
||||||
let mut paths = Vec::new();
|
let mut paths = Vec::new();
|
||||||
|
|
||||||
for line in reader.split(b'\0') {
|
for (i, line) in reader.split(b'\0').enumerate() {
|
||||||
let path = line?;
|
let path = line?;
|
||||||
if !path.is_empty() {
|
|
||||||
|
if path.is_empty() {
|
||||||
|
let line_number = i + 1;
|
||||||
|
show_error!("{file_name}:{line_number}: invalid zero-length file name");
|
||||||
|
set_exit_code(1);
|
||||||
|
} else {
|
||||||
paths.push(PathBuf::from(String::from_utf8_lossy(&path).to_string()));
|
paths.push(PathBuf::from(String::from_utf8_lossy(&path).to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1010,6 +1010,24 @@ fn test_du_files0_from() {
|
||||||
.stdout_contains("testdir");
|
.stdout_contains("testdir");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_du_files0_from_with_invalid_zero_length_file_names() {
|
||||||
|
let ts = TestScenario::new(util_name!());
|
||||||
|
let at = &ts.fixtures;
|
||||||
|
|
||||||
|
at.touch("testfile");
|
||||||
|
|
||||||
|
at.write("filelist", "\0testfile\0\0");
|
||||||
|
|
||||||
|
ts.ucmd()
|
||||||
|
.arg("--files0-from=filelist")
|
||||||
|
.fails()
|
||||||
|
.code_is(1)
|
||||||
|
.stdout_contains("testfile")
|
||||||
|
.stderr_contains("filelist:1: invalid zero-length file name")
|
||||||
|
.stderr_contains("filelist:3: invalid zero-length file name");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_du_files0_from_stdin() {
|
fn test_du_files0_from_stdin() {
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
|
@ -1028,6 +1046,17 @@ fn test_du_files0_from_stdin() {
|
||||||
.stdout_contains("testfile2");
|
.stdout_contains("testfile2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_du_files0_from_stdin_with_invalid_zero_length_file_names() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("--files0-from=-")
|
||||||
|
.pipe_in("\0\0")
|
||||||
|
.fails()
|
||||||
|
.code_is(1)
|
||||||
|
.stderr_contains("-:1: invalid zero-length file name")
|
||||||
|
.stderr_contains("-:2: invalid zero-length file name");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_du_files0_from_dir() {
|
fn test_du_files0_from_dir() {
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue