refactor: improve logging
Release / check-release (push) Successful in 15s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m43s
CI / Build Linux (push) Successful in 1m56s
Release / check-release (push) Successful in 15s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m43s
CI / Build Linux (push) Successful in 1m56s
This commit is contained in:
1 parent
d3b7d7a18f
commit
b65d5eb97c
8 files changed
+198
-44
No files matched your search
+15
-2
@@ -15,11 +15,16 @@
|
||||
use crate::plugin::Plugin;
|
||||
use std::path::Path;
|
||||
|
||||
#[tracing::instrument(skip(input, plugins))]
|
||||
pub fn identify_format(path: &str, input: &[u8], plugins: &[Box<dyn Plugin>]) -> Option<&'static str> {
|
||||
tracing::trace!("Identifying format for path: {}", path);
|
||||
let mut ext_str_opt = None;
|
||||
|
||||
if let Some(kind) = infer::get(input) {
|
||||
tracing::trace!("infer detected file type: {:?}", kind.mime_type());
|
||||
ext_str_opt = Some(kind.extension());
|
||||
} else if !input.is_empty() {
|
||||
tracing::trace!("infer failed to detect file type from magic bytes.");
|
||||
}
|
||||
|
||||
let p = Path::new(path);
|
||||
@@ -33,23 +38,31 @@ pub fn identify_format(path: &str, input: &[u8], plugins: &[Box<dyn Plugin>]) ->
|
||||
}
|
||||
|
||||
let mut ext_str = ext.as_deref().unwrap_or("");
|
||||
if ext_str_opt.is_some() {
|
||||
ext_str = ext_str_opt.unwrap();
|
||||
if let Some(magic_ext) = ext_str_opt {
|
||||
tracing::debug!("Using magic byte extension over path extension: {} -> {}", ext_str, magic_ext);
|
||||
ext_str = magic_ext;
|
||||
} else {
|
||||
tracing::debug!("Using path extension: {}", ext_str);
|
||||
}
|
||||
|
||||
let ext_str = match ext_str {
|
||||
"jpg" => "jpeg",
|
||||
other => other,
|
||||
};
|
||||
tracing::trace!("Normalized extension to check plugins against: {}", ext_str);
|
||||
|
||||
for plugin in plugins {
|
||||
tracing::trace!("Checking plugin {} formats for support of {}", plugin.name(), ext_str);
|
||||
if let Some(&f) = plugin.from_formats().iter().find(|&&f| f == ext_str) {
|
||||
tracing::debug!("Plugin {} supports {} as input.", plugin.name(), f);
|
||||
return Some(f);
|
||||
}
|
||||
if let Some(&f) = plugin.to_formats().iter().find(|&&f| f == ext_str) {
|
||||
tracing::debug!("Plugin {} supports {} as output.", plugin.name(), f);
|
||||
return Some(f);
|
||||
}
|
||||
}
|
||||
tracing::debug!("No plugin supports the format '{}'.", ext_str);
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user