2
0
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:
sharkdp 2018-05-08 23:22:27 +02:00
parent f7af537018
commit f90b9d1acc

View File

@ -27,6 +27,9 @@ use std::io::{self, BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
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::Style;
use atty::Stream;
@ -163,7 +166,21 @@ fn print_file(
let syntax = match (options.language, filename) {
(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,
};