mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
tail: improve error handling when file not found
This commit is contained in:
parent
ec386fa460
commit
e575007629
2 changed files with 13 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue