Do not show file header for directories

This also adds a better error message.

closes #292
This commit is contained in:
sharkdp 2018-09-12 21:53:41 +02:00
parent ea369ee17f
commit e098eb43a2
1 changed files with 9 additions and 1 deletions

View File

@ -53,7 +53,15 @@ impl<'b> Controller<'b> {
{
let reader: Box<BufRead> = match filename {
InputFile::StdIn => Box::new(stdin.lock()),
InputFile::Ordinary(filename) => Box::new(BufReader::new(File::open(filename)?)),
InputFile::Ordinary(filename) => {
let file = File::open(filename)?;
if file.metadata()?.is_dir() {
return Err(format!("'{}' is a directory.", filename).into());
}
Box::new(BufReader::new(file))
}
InputFile::ThemePreviewFile => Box::new(THEME_PREVIEW_FILE),
};