-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add list prefix support (#3728)
* Remove limit on list prefix Signed-off-by: Xuanwo <[email protected]> * Cover more test Signed-off-by: Xuanwo <[email protected]> * feat: Add list prefix support Signed-off-by: Xuanwo <[email protected]> * Add upgrade Signed-off-by: Xuanwo <[email protected]> --------- Signed-off-by: Xuanwo <[email protected]>
- Loading branch information
Showing
13 changed files
with
173 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::task::ready; | ||
use std::task::Context; | ||
use std::task::Poll; | ||
|
||
use crate::raw::*; | ||
use crate::*; | ||
|
||
/// PrefixLister is used to filter entries by prefix. | ||
/// | ||
/// For example, if we have a lister that returns entries: | ||
/// | ||
/// ```txt | ||
/// . | ||
/// ├── file_a | ||
/// └── file_b | ||
/// ``` | ||
/// | ||
/// We can use `PrefixLister` to filter entries with prefix `file_`. | ||
pub struct PrefixLister<L> { | ||
lister: L, | ||
prefix: String, | ||
} | ||
|
||
/// # Safety | ||
/// | ||
/// We will only take `&mut Self` reference for FsLister. | ||
unsafe impl<L> Sync for PrefixLister<L> {} | ||
|
||
impl<L> PrefixLister<L> { | ||
/// Create a new flat lister | ||
pub fn new(lister: L, prefix: &str) -> PrefixLister<L> { | ||
PrefixLister { | ||
lister, | ||
prefix: prefix.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl<L> oio::List for PrefixLister<L> | ||
where | ||
L: oio::List, | ||
{ | ||
fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Result<Option<oio::Entry>>> { | ||
loop { | ||
match ready!(self.lister.poll_next(cx)) { | ||
Ok(Some(e)) if !e.path().starts_with(&self.prefix) => continue, | ||
v => return Poll::Ready(v), | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<L> oio::BlockingList for PrefixLister<L> | ||
where | ||
L: oio::BlockingList, | ||
{ | ||
fn next(&mut self) -> Result<Option<oio::Entry>> { | ||
loop { | ||
match self.lister.next() { | ||
Ok(Some(e)) if !e.path().starts_with(&self.prefix) => continue, | ||
v => return v, | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.