fix(sdk): Fix resolving package wildcards
Directories were ignored as invalid extension type. Now they are recursed into.
This commit is contained in:
parent
214d481439
commit
733ade3887
3 changed files with 40 additions and 17 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -38,6 +38,17 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-recursion"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b015a331cc64ebd1774ba119538573603427eaace0a1950c423ab971f903796"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
|
@ -1097,6 +1108,7 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
|||
name = "sdk"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"async-recursion",
|
||||
"byteorder",
|
||||
"color-eyre",
|
||||
"csv-async",
|
||||
|
|
|
@ -21,3 +21,4 @@ tokio = { version = "1.21.2", features = ["rt-multi-thread", "fs", "process", "m
|
|||
tokio-stream = { version = "0.1.11", features = ["fs", "io-util"] }
|
||||
tracing = { version = "0.1.37", features = ["async-await"] }
|
||||
tracing-error = "0.2.0"
|
||||
async-recursion = "1.0.2"
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::ops::{Deref, DerefMut};
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
|
||||
use async_recursion::async_recursion;
|
||||
use color_eyre::eyre::{self, Context};
|
||||
use color_eyre::Result;
|
||||
use tokio::fs;
|
||||
|
@ -13,14 +14,15 @@ use crate::bundle::file::{BundleFileType, UserFile};
|
|||
use crate::murmur::{HashGroup, Murmur64};
|
||||
|
||||
#[tracing::instrument]
|
||||
#[async_recursion]
|
||||
async fn resolve_wildcard<P1, P2>(
|
||||
wildcard: P1,
|
||||
root: P2,
|
||||
t: Option<BundleFileType>,
|
||||
) -> Result<Vec<PathBuf>>
|
||||
where
|
||||
P1: AsRef<Path> + std::fmt::Debug,
|
||||
P2: AsRef<Path> + std::fmt::Debug,
|
||||
P1: AsRef<Path> + std::fmt::Debug + std::marker::Send,
|
||||
P2: AsRef<Path> + std::fmt::Debug + std::marker::Send + std::marker::Copy,
|
||||
{
|
||||
let wildcard = wildcard.as_ref();
|
||||
|
||||
|
@ -56,6 +58,12 @@ where
|
|||
path.to_path_buf()
|
||||
};
|
||||
|
||||
let meta = entry.metadata().await?;
|
||||
if meta.is_dir() {
|
||||
let wildcard = file_path.join("*");
|
||||
let inner_paths = resolve_wildcard(wildcard, root, t).await?;
|
||||
paths.extend_from_slice(&inner_paths);
|
||||
} else {
|
||||
// Skip file if there is a desired extension `t`, but the file's
|
||||
// extension name doesn't match
|
||||
if t.is_some() {
|
||||
|
@ -65,7 +73,7 @@ where
|
|||
.and_then(|ext| BundleFileType::from_str(ext).ok());
|
||||
|
||||
if ext != t {
|
||||
tracing::debug!(
|
||||
tracing::warn!(
|
||||
"Skipping wildcard result with invalid extension: {}",
|
||||
file_path.display(),
|
||||
);
|
||||
|
@ -73,8 +81,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
tracing::debug!("Found file {}", file_path.display());
|
||||
paths.push(file_path);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(paths)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue