From 0cf29089049155d708548a2ed1bae9d421484e13 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 908f449..dbfa6fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46016233fc1bb55c23b856fe556b7db6ccd05119a0a392e04f0b3b7c79058f16" +[[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 = "atk" version = "0.16.0" @@ -2007,6 +2018,7 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" name = "sdk" version = "0.2.0" dependencies = [ + "async-recursion", "bitflags", "byteorder", "color-eyre", diff --git a/lib/sdk/Cargo.toml b/lib/sdk/Cargo.toml index 5c2ef1a..0844518 100644 --- a/lib/sdk/Cargo.toml +++ b/lib/sdk/Cargo.toml @@ -23,3 +23,4 @@ tokio-stream = { version = "0.1.11", features = ["fs", "io-util"] } tracing = { version = "0.1.37", features = ["async-await"] } tracing-error = "0.2.0" luajit2-sys = "0.0.2" +async-recursion = "1.0.2" diff --git a/lib/sdk/src/filetype/package.rs b/lib/sdk/src/filetype/package.rs index 2dc9c3c..fc2e8f6 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)