Skip to content

Commit 7b4e4ad

Browse files
authored
fix(cubestore): Avoid empty result set with LocalDirRemoteFs:list_with_metadata on Windows (#9598)
1 parent eab3ce9 commit 7b4e4ad

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

rust/cubestore/cubestore/src/metastore/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6362,7 +6362,6 @@ mod tests {
63626362
let list = LocalDirRemoteFs::list_recursive(
63636363
config.remote_dir().clone(),
63646364
"metastore-".to_string(),
6365-
config.remote_dir().clone(),
63666365
)
63676366
.await
63686367
.unwrap();

rust/cubestore/cubestore/src/remotefs/mod.rs

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ impl RemoteFs for LocalDirRemoteFs {
346346
let result = Self::list_recursive(
347347
remote_dir.clone().unwrap_or(self.dir.clone()),
348348
remote_prefix.to_string(),
349-
remote_dir.unwrap_or(self.dir.clone()),
350349
)
351350
.await?;
352351
Ok(result)
@@ -395,45 +394,59 @@ impl LocalDirRemoteFs {
395394
Ok(())
396395
}
397396

398-
fn list_recursive_boxed(
397+
pub async fn list_recursive(
399398
remote_dir: PathBuf,
400399
remote_prefix: String,
401-
dir: PathBuf,
402-
) -> BoxFuture<'static, Result<Vec<RemoteFile>, CubeError>> {
403-
async move { Self::list_recursive(remote_dir, remote_prefix, dir).await }.boxed()
400+
) -> Result<Vec<RemoteFile>, CubeError> {
401+
let mut result_builder = Vec::new();
402+
Self::list_recursive_helper(
403+
remote_dir,
404+
remote_prefix,
405+
&mut result_builder,
406+
&mut PathBuf::new(),
407+
)
408+
.await?;
409+
Ok(result_builder)
404410
}
405411

406-
pub async fn list_recursive(
407-
remote_dir: PathBuf,
412+
fn list_recursive_boxed_helper<'a>(
413+
dir: PathBuf,
408414
remote_prefix: String,
415+
result_builder: &'a mut Vec<RemoteFile>,
416+
relative_prefix: &'a mut PathBuf,
417+
) -> BoxFuture<'a, Result<(), CubeError>> {
418+
async move {
419+
Self::list_recursive_helper(dir, remote_prefix, result_builder, relative_prefix).await
420+
}
421+
.boxed()
422+
}
423+
424+
async fn list_recursive_helper(
409425
dir: PathBuf,
410-
) -> Result<Vec<RemoteFile>, CubeError> {
411-
let mut result = Vec::new();
426+
remote_prefix: String,
427+
result_builder: &mut Vec<RemoteFile>,
428+
relative_prefix: &mut PathBuf,
429+
) -> Result<(), CubeError> {
412430
if fs::metadata(dir.clone()).await.is_err() {
413-
return Ok(vec![]);
431+
return Ok(());
414432
}
415433
if let Ok(mut dir) = fs::read_dir(dir).await {
416434
while let Ok(Some(file)) = dir.next_entry().await {
417435
if let Ok(true) = file.file_type().await.map(|r| r.is_dir()) {
418-
result.append(
419-
&mut Self::list_recursive_boxed(
420-
remote_dir.clone(),
421-
remote_prefix.to_string(),
422-
file.path(),
423-
)
424-
.await?,
425-
);
436+
relative_prefix.push(file.file_name());
437+
Self::list_recursive_boxed_helper(
438+
file.path(),
439+
remote_prefix.to_string(),
440+
result_builder,
441+
relative_prefix,
442+
)
443+
.await?;
444+
relative_prefix.pop();
426445
} else if let Ok(metadata) = file.metadata().await {
427-
let relative_name = file
428-
.path()
429-
.to_str()
430-
.unwrap()
431-
.to_string()
432-
.replace(&remote_dir.to_str().unwrap().to_string(), "")
433-
.trim_start_matches("/")
434-
.to_string();
446+
let relative_path = relative_prefix.join(file.file_name());
447+
let relative_name = relative_path.to_str().unwrap();
435448
if relative_name.starts_with(&remote_prefix) {
436-
result.push(RemoteFile {
449+
result_builder.push(RemoteFile {
437450
remote_path: relative_name.to_string(),
438451
updated: DateTime::from(metadata.modified()?),
439452
file_size: metadata.len(),
@@ -442,7 +455,7 @@ impl LocalDirRemoteFs {
442455
}
443456
}
444457
}
445-
Ok(result)
458+
Ok(())
446459
}
447460
}
448461

0 commit comments

Comments
 (0)