Skip to content

Commit 873786e

Browse files
committed
update fs trait impl
1 parent 85e77be commit 873786e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/store/fs.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,14 @@ pub(crate) enum ImportSource {
443443

444444
/// trait which defines the backend persistence layer
445445
/// for this store. e.g. filesystem, s3 etc
446-
pub trait Persistence: Clone {
446+
pub trait Persistence {
447447
/// the error type that is returned for the persistence layer
448448
type Err;
449449

450+
/// the type which represents a file which was read from the persistence
451+
/// layer
452+
type File;
453+
450454
/// return the size of the file in bytes if it can be found/read
451455
/// otherwise return a [Self::Err]
452456
fn size(&self, path: &Path) -> impl Future<Output = Result<u64, Self::Err>>;
@@ -458,6 +462,9 @@ pub trait Persistence: Clone {
458462

459463
/// recursively ensure that the input path exists
460464
fn create_dir_all(&self, path: &Path) -> impl Future<Output = Result<(), Self::Err>>;
465+
466+
/// read and return the file at the input path
467+
fn open(&self, path: &Path) -> impl Future<Output = Result<Self::File, Self::Err>>;
461468
}
462469

463470
/// A persistence layer that writes to the local file system
@@ -466,20 +473,22 @@ pub struct FileSystemPersistence;
466473

467474
impl Persistence for FileSystemPersistence {
468475
type Err = io::Error;
476+
type File = tokio::fs::File;
469477

470-
fn size(&self, path: &Path) -> impl Future<Output = Result<u64, Self::Err>> {
471-
let res = std::fs::metadata(path).map(|m| m.len());
472-
async move { res }
478+
async fn size(&self, path: &Path) -> Result<u64, Self::Err> {
479+
tokio::fs::metadata(path).await.map(|m| m.len())
473480
}
474481

475482
fn read(&self, path: &Path) -> impl Future<Output = Result<Vec<u8>, Self::Err>> {
476-
let res = std::fs::read(path);
477-
async move { res }
483+
tokio::fs::read(path)
478484
}
479485

480486
fn create_dir_all(&self, path: &Path) -> impl Future<Output = Result<(), Self::Err>> {
481-
let res = std::fs::create_dir_all(path);
482-
async move { res }
487+
tokio::fs::create_dir_all(path)
488+
}
489+
490+
fn open(&self, path: &Path) -> impl Future<Output = Result<Self::File, Self::Err>> {
491+
tokio::fs::File::open(path)
483492
}
484493
}
485494

0 commit comments

Comments
 (0)