1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #2886 from jfinkels/tail-io-error

tail: improve error handling when file not found
This commit is contained in:
Sylvestre Ledru 2022-01-18 09:21:57 +01:00 committed by GitHub
commit 13de6cabfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -30,7 +30,7 @@ use std::path::Path;
use std::thread::sleep;
use std::time::Duration;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::parse_size::{parse_size, ParseSizeError};
use uucore::ringbuffer::RingBuffer;
@ -220,7 +220,8 @@ fn uu_tail(settings: &Settings) -> UResult<()> {
if path.is_dir() {
continue;
}
let mut file = File::open(&path).unwrap();
let mut file = File::open(&path)
.map_err_context(|| format!("cannot open {} for reading", filename.quote()))?;
let md = file.metadata().unwrap();
if is_seekable(&mut file) && get_block_size(&md) > 0 {
bounded_tail(&mut file, settings);

View file

@ -3,7 +3,7 @@
// * For the full copyright and license information, please view the LICENSE
// * file that was distributed with this source code.
// spell-checker:ignore (ToDO) abcdefghijklmnopqrstuvwxyz efghijklmnopqrstuvwxyz vwxyz emptyfile
// spell-checker:ignore (ToDO) abcdefghijklmnopqrstuvwxyz efghijklmnopqrstuvwxyz vwxyz emptyfile bogusfile
extern crate tail;
@ -475,3 +475,12 @@ fn test_tail_bytes_for_funny_files() {
.code_is(exp_result.code());
}
}
#[test]
fn test_no_such_file() {
new_ucmd!()
.arg("bogusfile")
.fails()
.no_stdout()
.stderr_contains("cannot open 'bogusfile' for reading: No such file or directory");
}