From d0784d3741b60abc91f48493489ba8e49f4782f2 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 10 Jan 2024 14:51:35 +0800 Subject: [PATCH] fix(webserver): filter repository file without meta info (#1186) * fix(webserver): filter repository file without meta info * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- ee/tabby-webserver/src/repositories/mod.rs | 7 +++++-- ee/tabby-webserver/src/repositories/resolve.rs | 13 ++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ee/tabby-webserver/src/repositories/mod.rs b/ee/tabby-webserver/src/repositories/mod.rs index eb9ee4c22e45..0323e22db233 100644 --- a/ee/tabby-webserver/src/repositories/mod.rs +++ b/ee/tabby-webserver/src/repositories/mod.rs @@ -17,7 +17,7 @@ use tracing::{instrument, warn}; use crate::{ repositories::resolve::{ - resolve_all, resolve_dir, resolve_file, resolve_meta, Meta, ResolveParams, + contains_meta, resolve_all, resolve_dir, resolve_file, resolve_meta, Meta, ResolveParams, }, schema::auth::AuthenticationService, }; @@ -94,7 +94,7 @@ async fn resolve_path( .unwrap_or(false); if is_dir { - return match resolve_dir(root, full_path.clone()).await { + return match resolve_dir(repo.name_str(), root, full_path.clone()).await { Ok(resp) => Ok(resp), Err(err) => { warn!("failed to resolve_dir <{:?}>: {}", full_path, err); @@ -103,6 +103,9 @@ async fn resolve_path( }; } + if !contains_meta(&repo.dataset_key()) { + return Err(StatusCode::NOT_FOUND); + } match resolve_file(root, &repo).await { Ok(resp) => Ok(resp), Err(err) => { diff --git a/ee/tabby-webserver/src/repositories/resolve.rs b/ee/tabby-webserver/src/repositories/resolve.rs index 7e814055365b..ac1bd03fe084 100644 --- a/ee/tabby-webserver/src/repositories/resolve.rs +++ b/ee/tabby-webserver/src/repositories/resolve.rs @@ -131,7 +131,7 @@ fn load_meta() -> HashMap { } /// Resolve a directory -pub async fn resolve_dir(root: PathBuf, full_path: PathBuf) -> Result { +pub async fn resolve_dir(repo_name: &str, root: PathBuf, full_path: PathBuf) -> Result { let mut read_dir = tokio::fs::read_dir(full_path).await?; let mut entries: Vec = vec![]; @@ -148,6 +148,13 @@ pub async fn resolve_dir(root: PathBuf, full_path: PathBuf) -> Result let kind = if meta.is_dir() { DirEntryKind::Dir } else if meta.is_file() { + let key = DatasetKey { + repo_name: repo_name.to_string(), + rel_path: basename.clone(), + }; + if !contains_meta(&key) { + continue; + } DirEntryKind::File } else { // Skip others. @@ -187,6 +194,10 @@ pub fn resolve_meta(key: &DatasetKey) -> Option { None } +pub fn contains_meta(key: &DatasetKey) -> bool { + META.contains_key(key) +} + pub fn resolve_all(rs: Arc) -> Result { let entries: Vec<_> = rs .repositories