Skip to content

Commit

Permalink
file-driver: Better usability check
Browse files Browse the repository at this point in the history
Check if the 'file' utility is actually capable of handling mime-types.
This is true virtually everywhere, except for OpenBSD.
  • Loading branch information
chrissicool committed Jan 21, 2024
1 parent 92ffa33 commit 4718c43
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ impl Driver for FileDriver {
}

fn usable(&self) -> bool {
let mut cmd = Command::new("file");
cmd.args(["-b", "--mime-type"]);
cmd
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn().is_ok()
if let Ok(out) = Command::new("file").arg("-h").output() {
let s = String::from_utf8(out.stderr).unwrap_or_default();
if s.contains("--mime-type") {
return true;
}
}
false
}

fn run(&self, path: &Path) -> Result<String, Box<dyn Error>> {
Expand Down

0 comments on commit 4718c43

Please sign in to comment.