Skip to content

Commit

Permalink
Noop file system for placeholders and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Aug 15, 2024
1 parent 705e5ed commit 4b3093d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/file_systems/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ mod zip;

mod clipboard;

mod noop;

use crate::file_systems::aws_s3::AwsS3FileSystem;
use crate::file_systems::clipboard::ClipboardFileSystem;
use crate::file_tools::FileMatcher;
Expand Down
72 changes: 72 additions & 0 deletions src/file_systems/noop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use crate::errors::AppError;
use crate::file_systems::{AbsoluteFilePath, FileSystemConnection, FileSystemRef, ListFilesResult};
use crate::file_tools::FileMatcher;
use crate::reporter::AppReporter;
use crate::AppResult;
use bytes::Bytes;
use futures::Stream;
use rvstruct::ValueStruct;

pub struct NoopFileSystem<'a> {
reporter: &'a AppReporter<'a>,
}

impl<'a> NoopFileSystem<'a> {
#[allow(dead_code)]
pub fn new(reporter: &'a AppReporter<'a>) -> Self {
Self { reporter }
}
}

impl<'a> FileSystemConnection<'a> for NoopFileSystem<'a> {
async fn download(
&mut self,
_file_ref: Option<&FileSystemRef>,
) -> AppResult<(
FileSystemRef,
Box<dyn Stream<Item = AppResult<Bytes>> + Send + Sync + Unpin + 'static>,
)> {
Err(AppError::SystemError {
message: "NoopFileSystem does not support download".to_string(),
})
}

async fn upload<S: Stream<Item = AppResult<Bytes>> + Send + Unpin + Sync + 'static>(
&mut self,
_input: S,
_file_ref: Option<&FileSystemRef>,
) -> AppResult<()> {
Err(AppError::SystemError {
message: "NoopFileSystem does not support upload".to_string(),
})
}

async fn list_files(
&mut self,
_file_matcher: Option<&FileMatcher>,
) -> AppResult<ListFilesResult> {
self.reporter
.report("NoopFileSystem does not support list_files")?;
Ok(ListFilesResult::EMPTY)
}

async fn close(self) -> AppResult<()> {
Ok(())
}

async fn has_multiple_files(&self) -> AppResult<bool> {
Ok(false)
}

async fn accepts_multiple_files(&self) -> AppResult<bool> {
Ok(false)
}

fn resolve(&self, file_ref: Option<&FileSystemRef>) -> AbsoluteFilePath {
AbsoluteFilePath {
file_path: file_ref
.map(|fr| fr.relative_path.value().clone())
.unwrap_or("".to_string()),
}
}
}

0 comments on commit 4b3093d

Please sign in to comment.