mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-21 23:33:26 +01:00
Throw an error when try to read a block device
This commit is contained in:
parent
e608b33142
commit
483b1dbdd8
@ -48,6 +48,7 @@
|
|||||||
- Support 'statically linked binary' for aarch64 in 'Release' page, see #2992 (@tzq0301)
|
- Support 'statically linked binary' for aarch64 in 'Release' page, see #2992 (@tzq0301)
|
||||||
- Update options in shell completions and the man page of `bat`, see #2995 (@akinomyoga)
|
- Update options in shell completions and the man page of `bat`, see #2995 (@akinomyoga)
|
||||||
- Update nix dev-dependency to v0.29.0, see #3112 (@decathorpe)
|
- Update nix dev-dependency to v0.29.0, see #3112 (@decathorpe)
|
||||||
|
- Throw an error when try to read a block device, see #3128 (@Integral-Tech)
|
||||||
|
|
||||||
## Syntaxes
|
## Syntaxes
|
||||||
|
|
||||||
|
13
src/input.rs
13
src/input.rs
@ -4,6 +4,9 @@ use std::fs::File;
|
|||||||
use std::io::{self, BufRead, BufReader, Read};
|
use std::io::{self, BufRead, BufReader, Read};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
use std::os::unix::fs::FileTypeExt;
|
||||||
|
|
||||||
use clircle::{Clircle, Identifier};
|
use clircle::{Clircle, Identifier};
|
||||||
use content_inspector::{self, ContentType};
|
use content_inspector::{self, ContentType};
|
||||||
|
|
||||||
@ -218,10 +221,18 @@ impl<'a> Input<'a> {
|
|||||||
reader: {
|
reader: {
|
||||||
let mut file = File::open(&path)
|
let mut file = File::open(&path)
|
||||||
.map_err(|e| format!("'{}': {}", path.to_string_lossy(), e))?;
|
.map_err(|e| format!("'{}': {}", path.to_string_lossy(), e))?;
|
||||||
if file.metadata()?.is_dir() {
|
let metadata = file.metadata()?;
|
||||||
|
if metadata.is_dir() {
|
||||||
return Err(format!("'{}' is a directory.", path.to_string_lossy()).into());
|
return Err(format!("'{}' is a directory.", path.to_string_lossy()).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
if metadata.file_type().is_block_device() {
|
||||||
|
return Err(
|
||||||
|
format!("'{}' is a block device.", path.to_string_lossy()).into()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(stdout) = stdout_identifier {
|
if let Some(stdout) = stdout_identifier {
|
||||||
let input_identifier = Identifier::try_from(file).map_err(|e| {
|
let input_identifier = Identifier::try_from(file).map_err(|e| {
|
||||||
format!("{}: Error identifying file: {}", path.to_string_lossy(), e)
|
format!("{}: Error identifying file: {}", path.to_string_lossy(), e)
|
||||||
|
Loading…
Reference in New Issue
Block a user