Skip to content

Commit

Permalink
fix(webserver): filter repository file without meta info (#1186)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
darknight and autofix-ci[bot] authored Jan 10, 2024
1 parent fd22fb9 commit d0784d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ee/tabby-webserver/src/repositories/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);
Expand All @@ -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) => {
Expand Down
13 changes: 12 additions & 1 deletion ee/tabby-webserver/src/repositories/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn load_meta() -> HashMap<DatasetKey, Meta> {
}

/// Resolve a directory
pub async fn resolve_dir(root: PathBuf, full_path: PathBuf) -> Result<Response> {
pub async fn resolve_dir(repo_name: &str, root: PathBuf, full_path: PathBuf) -> Result<Response> {
let mut read_dir = tokio::fs::read_dir(full_path).await?;
let mut entries: Vec<DirEntry> = vec![];

Expand All @@ -148,6 +148,13 @@ pub async fn resolve_dir(root: PathBuf, full_path: PathBuf) -> Result<Response>
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.
Expand Down Expand Up @@ -187,6 +194,10 @@ pub fn resolve_meta(key: &DatasetKey) -> Option<Meta> {
None
}

pub fn contains_meta(key: &DatasetKey) -> bool {
META.contains_key(key)
}

pub fn resolve_all(rs: Arc<ResolveState>) -> Result<Response> {
let entries: Vec<_> = rs
.repositories
Expand Down

0 comments on commit d0784d3

Please sign in to comment.