From 075f4d62989acad0c13e782aa02587cd451cb327 Mon Sep 17 00:00:00 2001 From: Kebe Date: Thu, 30 Nov 2023 17:19:22 +0800 Subject: [PATCH] fix(oli): Fix cp -r command returns invalid path error (#3687) Fix cp -r command returns invalid path error Signed-off-by: Kebe --- bin/oli/src/commands/cp.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/oli/src/commands/cp.rs b/bin/oli/src/commands/cp.rs index 609b3d48be5e..216fddbe5d5f 100644 --- a/bin/oli/src/commands/cp.rs +++ b/bin/oli/src/commands/cp.rs @@ -57,13 +57,18 @@ pub async fn main(args: &ArgMatches) -> Result<()> { let dst_root = Path::new(&dst_path); let mut ds = src_op.lister_with(&src_path).recursive(true).await?; + let prefix = src_path.strip_prefix('/').unwrap_or(src_path.as_str()); while let Some(de) = ds.try_next().await? { let meta = de.metadata(); if meta.mode().is_dir() { continue; } - - let fp = de.path().strip_prefix(&src_path).expect("invalid path"); + let depath = de.path(); + let fp = depath + .strip_prefix('/') + .unwrap_or(depath) + .strip_prefix(prefix) + .expect("invalid path"); let reader = src_op.reader(de.path()).await?; let buf_reader = futures::io::BufReader::with_capacity(8 * 1024 * 1024, reader);