You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/03/26 23:30:20 UTC
[incubator-opendal] branch main updated: refactor(oli): switch to `Operator::scan` and `Operator::remove_all` (#1779)
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 1d563b42 refactor(oli): switch to `Operator::scan` and `Operator::remove_all` (#1779)
1d563b42 is described below
commit 1d563b42e10834d3726ef71458d2cea6c948351c
Author: Jian Zeng <an...@gmail.com>
AuthorDate: Mon Mar 27 07:30:16 2023 +0800
refactor(oli): switch to `Operator::scan` and `Operator::remove_all` (#1779)
refactor: exploit magic in opendal
Signed-off-by: Jian Zeng <an...@gmail.com>
---
bin/oli/src/commands/ls.rs | 18 +++---------------
bin/oli/src/commands/rm.rs | 21 ++-------------------
2 files changed, 5 insertions(+), 34 deletions(-)
diff --git a/bin/oli/src/commands/ls.rs b/bin/oli/src/commands/ls.rs
index 323efaf4..db6d1d69 100644
--- a/bin/oli/src/commands/ls.rs
+++ b/bin/oli/src/commands/ls.rs
@@ -15,13 +15,11 @@
// specific language governing permissions and limitations
// under the License.
-use std::collections::VecDeque;
use std::path::PathBuf;
use anyhow::{anyhow, Result};
use clap::{Arg, ArgAction, ArgMatches, Command};
use futures::TryStreamExt;
-use opendal::Metakey;
use crate::config::Config;
@@ -46,19 +44,9 @@ pub async fn main(args: &ArgMatches) -> Result<()> {
return Ok(());
}
- let mut queue = VecDeque::from([path.to_string()]);
- while !queue.is_empty() {
- let path = queue.pop_front().unwrap();
- let mut ds = op.list(&path).await?;
- while let Some(de) = ds.try_next().await? {
- let meta = op.metadata(&de, Metakey::Mode).await?;
- if meta.mode().is_dir() {
- let d = de.path().to_owned();
- queue.push_back(d);
- } else {
- println!("{}", de.path());
- }
- }
+ let mut ds = op.scan(&path).await?;
+ while let Some(de) = ds.try_next().await? {
+ println!("{}", de.path());
}
Ok(())
}
diff --git a/bin/oli/src/commands/rm.rs b/bin/oli/src/commands/rm.rs
index df72a0fc..d4855557 100644
--- a/bin/oli/src/commands/rm.rs
+++ b/bin/oli/src/commands/rm.rs
@@ -15,13 +15,10 @@
// specific language governing permissions and limitations
// under the License.
-use std::collections::VecDeque;
use std::path::PathBuf;
use anyhow::{anyhow, Result};
use clap::{Arg, ArgAction, ArgMatches, Command};
-use futures::TryStreamExt;
-use opendal::Metakey;
use crate::config::Config;
@@ -44,22 +41,8 @@ pub async fn main(args: &ArgMatches) -> Result<()> {
return Ok(());
}
- let mut queue = VecDeque::from([path.to_string()]);
- while !queue.is_empty() {
- let path = queue.pop_front().unwrap();
- let mut ds = op.list(&path).await?;
- while let Some(de) = ds.try_next().await? {
- let meta = op.metadata(&de, Metakey::Mode).await?;
- if meta.mode().is_dir() {
- let d = de.path().to_owned();
- queue.push_back(d);
- } else {
- let path = de.path();
- println!("Delete: {path}");
- op.delete(path).await?;
- }
- }
- }
+ println!("Delete all: {path}");
+ op.remove_all(&path).await?;
Ok(())
}