This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 075f4d629 fix(oli): Fix cp -r command returns invalid path error 
(#3687)
075f4d629 is described below

commit 075f4d62989acad0c13e782aa02587cd451cb327
Author: Kebe <[email protected]>
AuthorDate: Thu Nov 30 17:19:22 2023 +0800

    fix(oli): Fix cp -r command returns invalid path error (#3687)
    
    Fix cp -r command returns invalid path error
    
    Signed-off-by: Kebe <[email protected]>
---
 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 609b3d48b..216fddbe5 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);
 

Reply via email to