From 733ade3887be867db2ba0d0e72b68c5bd7960efe Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Wed, 22 Feb 2023 16:03:59 +0100 Subject: [PATCH] fix(sdk): Fix resolving package wildcards Directories were ignored as invalid extension type. Now they are recursed into. --- Cargo.lock | 12 +++++++++ lib/sdk/Cargo.toml | 1 + lib/sdk/src/filetype/package.rs | 44 ++++++++++++++++++++------------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb88a6c..b409111 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/lib/sdk/Cargo.toml b/lib/sdk/Cargo.toml index 02f3964..7a1857b 100644 --- a/lib/sdk/Cargo.toml +++ b/lib/sdk/Cargo.toml @@ -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" diff --git a/lib/sdk/src/filetype/package.rs b/lib/sdk/src/filetype/package.rs index 36e3575..63ec712 100644 --- a/lib/sdk/src/filetype/package.rs +++ b/lib/sdk/src/filetype/package.rs @@ -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( wildcard: P1, root: P2, t: Option, ) -> Result> where - P1: AsRef + std::fmt::Debug, - P2: AsRef + std::fmt::Debug, + P1: AsRef + std::fmt::Debug + std::marker::Send, + P2: AsRef + std::fmt::Debug + std::marker::Send + std::marker::Copy, { let wildcard = wildcard.as_ref(); @@ -56,24 +58,32 @@ where path.to_path_buf() }; - // Skip file if there is a desired extension `t`, but the file's - // extension name doesn't match - if t.is_some() { - let ext = file_path - .extension() - .and_then(|ext| ext.to_str()) - .and_then(|ext| BundleFileType::from_str(ext).ok()); + 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() { + let ext = file_path + .extension() + .and_then(|ext| ext.to_str()) + .and_then(|ext| BundleFileType::from_str(ext).ok()); - if ext != t { - tracing::debug!( - "Skipping wildcard result with invalid extension: {}", - file_path.display(), - ); - continue; + if ext != t { + tracing::warn!( + "Skipping wildcard result with invalid extension: {}", + file_path.display(), + ); + continue; + } } - } - paths.push(file_path); + tracing::debug!("Found file {}", file_path.display()); + paths.push(file_path); + } } Ok(paths)