mirror of
https://github.com/sharkdp/bat
synced 2024-11-16 21:25:56 +00:00
Do not peek at FIFOs, closes #80
This commit is contained in:
parent
f7af537018
commit
f90b9d1acc
19
src/main.rs
19
src/main.rs
@ -27,6 +27,9 @@ use std::io::{self, BufRead, BufReader, Write};
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{self, Child, Command, Stdio};
|
use std::process::{self, Child, Command, Stdio};
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::fs::FileTypeExt;
|
||||||
|
|
||||||
use ansi_term::Colour::{Fixed, Green, Red, White, Yellow};
|
use ansi_term::Colour::{Fixed, Green, Red, White, Yellow};
|
||||||
use ansi_term::Style;
|
use ansi_term::Style;
|
||||||
use atty::Stream;
|
use atty::Stream;
|
||||||
@ -163,7 +166,21 @@ fn print_file(
|
|||||||
|
|
||||||
let syntax = match (options.language, filename) {
|
let syntax = match (options.language, filename) {
|
||||||
(Some(language), _) => syntax_set.find_syntax_by_token(language),
|
(Some(language), _) => syntax_set.find_syntax_by_token(language),
|
||||||
(None, Some(filename)) => syntax_set.find_syntax_for_file(filename)?,
|
(None, Some(filename)) => {
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
let may_read_from_file = true;
|
||||||
|
|
||||||
|
// Do not peek at the file (to determine the syntax) if it is a FIFO because they can
|
||||||
|
// only be read once.
|
||||||
|
#[cfg(unix)]
|
||||||
|
let may_read_from_file = !fs::metadata(filename)?.file_type().is_fifo();
|
||||||
|
|
||||||
|
if may_read_from_file {
|
||||||
|
syntax_set.find_syntax_for_file(filename)?
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
(None, None) => None,
|
(None, None) => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user