chore: add more logs to file

This commit is contained in:
sxyazi 2023-09-02 11:45:21 +08:00
parent 96cb7b6cc8
commit 66aecd5402
No known key found for this signature in database

View file

@ -1,8 +1,10 @@
use std::{collections::BTreeMap, ffi::OsStr, path::PathBuf};
use anyhow::{bail, Result};
use futures::TryFutureExt;
use shared::MimeKind;
use tokio::process::Command;
use tracing::error;
pub async fn file(files: &[impl AsRef<OsStr>]) -> Result<BTreeMap<PathBuf, String>> {
if files.is_empty() {
@ -14,6 +16,7 @@ pub async fn file(files: &[impl AsRef<OsStr>]) -> Result<BTreeMap<PathBuf, Strin
.args(files)
.kill_on_drop(true)
.output()
.inspect_err(|e| error!("failed to execute `file`: {}", e))
.await?;
let output = String::from_utf8_lossy(&output.stdout);
@ -26,6 +29,7 @@ pub async fn file(files: &[impl AsRef<OsStr>]) -> Result<BTreeMap<PathBuf, Strin
);
if mimes.is_empty() {
error!("failed to get mime types: {:?}", files.iter().map(AsRef::as_ref).collect::<Vec<_>>());
bail!("failed to get mime types");
}
Ok(mimes)