Skip to content

Commit

Permalink
du: prepare tests/du/files0-from.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Dec 24, 2023
1 parent afbdaa3 commit de85d89
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,20 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
));
}

// Read from a file
Box::new(BufReader::new(File::open(file_name)?))
// Attempt to open the file and handle the error if it does not exist
match File::open(file_name) {
Ok(file) => Box::new(BufReader::new(file)),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"cannot open '{}' for reading: No such file or directory",
file_name
),
))
}
Err(e) => return Err(e),

Check warning on line 618 in src/uu/du/src/du.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/du/src/du.rs#L618

Added line #L618 was not covered by tests
}
};

let mut paths = Vec::new();
Expand Down Expand Up @@ -634,6 +646,17 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
)?;

let files = if let Some(file_from) = matches.get_one::<String>(options::FILES0_FROM) {
if file_from == "-" && matches.get_one::<String>(options::FILE).is_some() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!(
"extra operand {}\nfile operands cannot be combined with --files0-from",
matches.get_one::<String>(options::FILE).unwrap().quote()
),
)
.into());
}

// Read file paths from the specified file, separated by null characters
read_files_from(file_from)?
} else {
Expand Down
4 changes: 4 additions & 0 deletions util/build-gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ sed -i -E "s|^([^#]*2_31.*)$|#\1|g" tests/printf/printf-cov.pl

sed -i -e "s/du: invalid -t argument/du: invalid --threshold argument/" -e "s/du: option requires an argument/error: a value is required for '--threshold <SIZE>' but none was supplied/" -e "/Try 'du --help' for more information./d" tests/du/threshold.sh

# Remove the extra output check
sed -i -e "s|Try '\$prog --help' for more information.\\\n||" tests/du/files0-from.pl
sed -i -e "s|when reading file names from stdin, no file name of\"|-: No such file or directory\n\"|" -e "s| '-' allowed\\\n||" tests/du/files0-from.pl

awk 'BEGIN {count=0} /compare exp out2/ && count < 6 {sub(/compare exp out2/, "grep -q \"cannot be used with\" out2"); count++} 1' tests/df/df-output.sh > tests/df/df-output.sh.tmp && mv tests/df/df-output.sh.tmp tests/df/df-output.sh

# with ls --dired, in case of error, we have a slightly different error position
Expand Down

0 comments on commit de85d89

Please sign in to comment.