refactor file system operations
the most notable improvement is that uploads are now using streams so they no longer require the entire file to be stored in memory
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
use anyhow::{Context, anyhow, bail};
|
||||
use futures_util::TryStreamExt;
|
||||
use rustix::fs::statx;
|
||||
use tokio::{
|
||||
fs,
|
||||
@@ -11,12 +12,14 @@ use tokio_util::io::ReaderStream;
|
||||
use crate::{
|
||||
config::Config,
|
||||
domain::warren::{
|
||||
models::file::{
|
||||
AbsoluteFilePath, CreateDirectoryError, CreateDirectoryRequest, CreateFileError,
|
||||
CreateFileRequest, DeleteDirectoryError, DeleteDirectoryRequest, DeleteFileError,
|
||||
DeleteFileRequest, FetchFileError, FetchFileRequest, File, FileMimeType, FileName,
|
||||
FilePath, FileStream, FileType, ListFilesError, ListFilesRequest, RenameEntryError,
|
||||
RenameEntryRequest,
|
||||
models::{
|
||||
file::{
|
||||
AbsoluteFilePath, CatError, CatRequest, File, FileMimeType, FileName, FilePath,
|
||||
FileStream, FileType, LsError, LsRequest, MkdirError, MkdirRequest, MvError,
|
||||
MvRequest, RelativeFilePath, RmError, RmRequest, SaveError, SaveRequest,
|
||||
SaveResponse, TouchError, TouchRequest,
|
||||
},
|
||||
warren::UploadFileStream,
|
||||
},
|
||||
ports::FileSystemRepository,
|
||||
},
|
||||
@@ -129,49 +132,65 @@ impl FileSystem {
|
||||
/// Actually created a directory in the underlying file system
|
||||
///
|
||||
/// * `path`: The directory's absolute path (absolute not in relation to the root file system but `self.base_directory`)
|
||||
async fn create_dir(&self, path: &AbsoluteFilePath) -> io::Result<FilePath> {
|
||||
async fn mkdir(&self, path: &AbsoluteFilePath) -> io::Result<()> {
|
||||
let file_path = self.get_target_path(path);
|
||||
|
||||
if fs::try_exists(&file_path).await? {
|
||||
return Err(io::ErrorKind::AlreadyExists.into());
|
||||
}
|
||||
|
||||
fs::create_dir(&file_path).await?;
|
||||
|
||||
Ok(file_path)
|
||||
fs::create_dir(&file_path).await
|
||||
}
|
||||
|
||||
/// Actually removes a directory from the underlying file system
|
||||
/// Actually removes a file or directory from the underlying file system
|
||||
///
|
||||
/// * `path`: The directory's absolute path (absolute not in relation to the root file system but `self.base_directory`)
|
||||
/// * `force`: Whether to delete directories that are not empty
|
||||
async fn remove_dir(&self, path: &AbsoluteFilePath, force: bool) -> io::Result<FilePath> {
|
||||
async fn rm(&self, path: &AbsoluteFilePath, force: bool) -> io::Result<()> {
|
||||
let file_path = self.get_target_path(path);
|
||||
|
||||
if force {
|
||||
fs::remove_dir_all(&file_path).await?;
|
||||
} else {
|
||||
fs::remove_dir(&file_path).await?;
|
||||
if fs::metadata(&file_path).await?.is_file() {
|
||||
return fs::remove_file(&file_path).await;
|
||||
}
|
||||
|
||||
Ok(file_path)
|
||||
if force {
|
||||
fs::remove_dir_all(&file_path).await
|
||||
} else {
|
||||
fs::remove_dir(&file_path).await
|
||||
}
|
||||
}
|
||||
|
||||
async fn write_file(&self, path: &AbsoluteFilePath, data: &[u8]) -> anyhow::Result<FilePath> {
|
||||
let path = self.get_target_path(path);
|
||||
async fn save(
|
||||
&self,
|
||||
path: &AbsoluteFilePath,
|
||||
stream: &mut UploadFileStream<'_>,
|
||||
) -> anyhow::Result<Vec<AbsoluteFilePath>> {
|
||||
let base_path = self.get_target_path(path);
|
||||
|
||||
let mut file = fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(&path)
|
||||
.await?;
|
||||
let paths = Vec::new();
|
||||
|
||||
file.write_all(data).await?;
|
||||
while let Ok(Some(mut upload_file)) = stream.try_next().await {
|
||||
// TODO: Refactor this result question mark chain thing
|
||||
let file_name_as_path: RelativeFilePath =
|
||||
FilePath::new(upload_file.file_name().as_str())?.try_into()?;
|
||||
let file_path = base_path.join(&file_name_as_path);
|
||||
|
||||
Ok(path)
|
||||
let mut file = fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(&file_path)
|
||||
.await?;
|
||||
|
||||
while let Ok(Some(chunk)) = upload_file.try_next().await {
|
||||
tracing::info!("Writing chunk (len: {}) to {file_path}", chunk.len());
|
||||
file.write(&chunk).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(paths)
|
||||
}
|
||||
|
||||
async fn fetch_file(&self, path: &AbsoluteFilePath) -> anyhow::Result<FileStream> {
|
||||
async fn cat(&self, path: &AbsoluteFilePath) -> anyhow::Result<FileStream> {
|
||||
let path = self.get_target_path(path);
|
||||
|
||||
let file = fs::OpenOptions::new()
|
||||
@@ -192,45 +211,30 @@ impl FileSystem {
|
||||
Ok(stream)
|
||||
}
|
||||
|
||||
/// Actually removes a file from the underlying file system
|
||||
///
|
||||
/// * `path`: The file's absolute path (absolute not in relation to the root file system but `self.base_directory`)
|
||||
async fn remove_file(&self, path: &AbsoluteFilePath) -> anyhow::Result<FilePath> {
|
||||
let path = self.get_target_path(path);
|
||||
|
||||
fs::remove_file(&path).await?;
|
||||
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
async fn rename(
|
||||
&self,
|
||||
path: &AbsoluteFilePath,
|
||||
new_name: &FileName,
|
||||
) -> anyhow::Result<FilePath> {
|
||||
async fn mv(&self, path: &AbsoluteFilePath, target_path: &AbsoluteFilePath) -> io::Result<()> {
|
||||
let current_path = self.get_target_path(path);
|
||||
let target_path = self.get_target_path(target_path);
|
||||
|
||||
let new_path = {
|
||||
let mut c = current_path.to_string();
|
||||
let last_slash_index = c.rfind('/').unwrap();
|
||||
c.drain((last_slash_index + 1)..);
|
||||
c.push_str(new_name.as_str());
|
||||
|
||||
FilePath::new(&c)?
|
||||
};
|
||||
|
||||
if fs::try_exists(&new_path).await? {
|
||||
bail!("File exists");
|
||||
if !fs::try_exists(¤t_path).await? {
|
||||
return Err(io::ErrorKind::NotFound.into());
|
||||
}
|
||||
|
||||
fs::rename(current_path, &new_path).await?;
|
||||
if fs::try_exists(&target_path).await? {
|
||||
return Err(io::ErrorKind::AlreadyExists.into());
|
||||
}
|
||||
|
||||
Ok(new_path)
|
||||
fs::rename(current_path, &target_path).await
|
||||
}
|
||||
|
||||
async fn touch(&self, path: &AbsoluteFilePath) -> io::Result<()> {
|
||||
let path = self.get_target_path(path);
|
||||
|
||||
tokio::fs::File::create(&path).await.map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSystemRepository for FileSystem {
|
||||
async fn list_files(&self, request: ListFilesRequest) -> Result<Vec<File>, ListFilesError> {
|
||||
async fn ls(&self, request: LsRequest) -> Result<Vec<File>, LsError> {
|
||||
let files = self.get_all_files(request.path()).await.map_err(|err| {
|
||||
anyhow!(err).context(format!(
|
||||
"Failed to get the files at path: {}",
|
||||
@@ -241,81 +245,56 @@ impl FileSystemRepository for FileSystem {
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
async fn create_directory(
|
||||
&self,
|
||||
request: CreateDirectoryRequest,
|
||||
) -> Result<FilePath, CreateDirectoryError> {
|
||||
match self.create_dir(request.path()).await {
|
||||
Ok(path) => Ok(path),
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::AlreadyExists => Err(CreateDirectoryError::Exists),
|
||||
_ => Err(anyhow!("Failed to create directory at path: {}", request.path()).into()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn delete_directory(
|
||||
&self,
|
||||
request: DeleteDirectoryRequest,
|
||||
) -> Result<FilePath, DeleteDirectoryError> {
|
||||
match self.remove_dir(request.path(), request.force()).await {
|
||||
Ok(deleted_path) => return Ok(deleted_path),
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => Err(DeleteDirectoryError::NotFound),
|
||||
std::io::ErrorKind::DirectoryNotEmpty => Err(DeleteDirectoryError::NotEmpty),
|
||||
_ => Err(anyhow!("Failed to delete directory at {}: {e:?}", request.path()).into()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_file(&self, request: CreateFileRequest) -> Result<FilePath, CreateFileError> {
|
||||
let file_path = self
|
||||
.write_file(request.path(), request.data())
|
||||
async fn cat(&self, request: CatRequest) -> Result<FileStream, CatError> {
|
||||
self.cat(request.path())
|
||||
.await
|
||||
.map_err(|e| {
|
||||
anyhow!(
|
||||
"Failed to write {} byte(s) to path {}: {e:?}",
|
||||
request.data().len(),
|
||||
request.path()
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(file_path)
|
||||
.map_err(|e| anyhow!("Failed to fetch file {}: {e:?}", request.path()).into())
|
||||
}
|
||||
|
||||
async fn fetch_file(&self, request: FetchFileRequest) -> Result<FileStream, FetchFileError> {
|
||||
let contents = self
|
||||
.fetch_file(request.path())
|
||||
async fn mkdir(&self, request: MkdirRequest) -> Result<(), MkdirError> {
|
||||
self.mkdir(request.path())
|
||||
.await
|
||||
.map_err(|e| anyhow!("Failed to fetch file {}: {e:?}", request.path()))?;
|
||||
|
||||
Ok(contents)
|
||||
.map_err(|e| match e.kind() {
|
||||
std::io::ErrorKind::AlreadyExists => MkdirError::Exists,
|
||||
_ => anyhow!("Failed to create directory at path: {}", request.path()).into(),
|
||||
})
|
||||
}
|
||||
|
||||
async fn delete_file(&self, request: DeleteFileRequest) -> Result<FilePath, DeleteFileError> {
|
||||
let deleted_path = self
|
||||
.remove_file(request.path())
|
||||
async fn rm(&self, request: RmRequest) -> Result<(), RmError> {
|
||||
self.rm(request.path(), request.force())
|
||||
.await
|
||||
.context(format!("Failed to delete file at {}", request.path()))?;
|
||||
|
||||
Ok(deleted_path)
|
||||
.map_err(|e| match e.kind() {
|
||||
std::io::ErrorKind::NotFound => RmError::NotFound,
|
||||
std::io::ErrorKind::DirectoryNotEmpty => RmError::NotEmpty,
|
||||
_ => anyhow!("Failed to delete file at {}: {e:?}", request.path()).into(),
|
||||
})
|
||||
}
|
||||
|
||||
async fn rename_entry(
|
||||
&self,
|
||||
request: RenameEntryRequest,
|
||||
) -> Result<FilePath, RenameEntryError> {
|
||||
let new_path = self
|
||||
.rename(request.path(), request.new_name())
|
||||
async fn mv(&self, request: MvRequest) -> Result<(), MvError> {
|
||||
self.mv(request.path(), request.target_path())
|
||||
.await
|
||||
.map_err(|e| {
|
||||
anyhow!(
|
||||
"Failed to rename {} to {}: {e:?}",
|
||||
.map_err(|e| match e.kind() {
|
||||
std::io::ErrorKind::NotFound => MvError::NotFound,
|
||||
_ => anyhow!(
|
||||
"Failed to move {} to {}: {e:?}",
|
||||
request.path(),
|
||||
request.new_name()
|
||||
request.target_path()
|
||||
)
|
||||
})?;
|
||||
.into(),
|
||||
})
|
||||
}
|
||||
|
||||
Ok(new_path)
|
||||
async fn touch(&self, request: TouchRequest) -> Result<(), TouchError> {
|
||||
self.touch(request.path())
|
||||
.await
|
||||
.map_err(|e| match e.kind() {
|
||||
std::io::ErrorKind::NotFound => TouchError::NotFound,
|
||||
_ => anyhow!("Failed to touch path {}: {e:?}", request.path()).into(),
|
||||
})
|
||||
}
|
||||
|
||||
async fn save(&self, request: SaveRequest<'_>) -> Result<SaveResponse, SaveError> {
|
||||
let (path, mut stream) = request.unpack();
|
||||
Ok(self.save(&path, &mut stream).await.map(SaveResponse::new)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,114 +52,104 @@ impl WarrenMetrics for MetricsDebugLogger {
|
||||
tracing::debug!("[Metrics] Fetch warrens failed");
|
||||
}
|
||||
|
||||
async fn record_warren_fetch_file_success(&self) {
|
||||
tracing::debug!("[Metrics] Fetch warren file succeeded");
|
||||
}
|
||||
async fn record_warren_fetch_file_failure(&self) {
|
||||
tracing::debug!("[Metrics] Fetch warren file failed");
|
||||
}
|
||||
|
||||
async fn record_list_warren_files_success(&self) {
|
||||
async fn record_warren_ls_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren list files succeeded");
|
||||
}
|
||||
|
||||
async fn record_list_warren_files_failure(&self) {
|
||||
async fn record_warren_ls_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren list files failed");
|
||||
}
|
||||
|
||||
async fn record_warren_directory_creation_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren directory creation succeeded");
|
||||
async fn record_warren_cat_success(&self) {
|
||||
tracing::debug!("[Metrics] Fetch warren file succeeded");
|
||||
}
|
||||
async fn record_warren_cat_failure(&self) {
|
||||
tracing::debug!("[Metrics] Fetch warren file failed");
|
||||
}
|
||||
|
||||
async fn record_warren_directory_creation_failure(&self) {
|
||||
async fn record_warren_mkdir_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren directory creation succeeded");
|
||||
}
|
||||
async fn record_warren_mkdir_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren directory creation failed");
|
||||
}
|
||||
|
||||
async fn record_warren_directory_deletion_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren directory deletion succeeded");
|
||||
}
|
||||
|
||||
async fn record_warren_directory_deletion_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren directory deletion failed");
|
||||
}
|
||||
|
||||
async fn record_warren_file_upload_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren file upload succeeded");
|
||||
}
|
||||
async fn record_warren_file_upload_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren file upload failed");
|
||||
}
|
||||
|
||||
async fn record_warren_files_upload_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren files upload succeded");
|
||||
}
|
||||
async fn record_warren_files_upload_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren files upload failed at least partially");
|
||||
}
|
||||
|
||||
async fn record_warren_file_deletion_success(&self) {
|
||||
async fn record_warren_rm_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren file deletion succeeded");
|
||||
}
|
||||
async fn record_warren_file_deletion_failure(&self) {
|
||||
async fn record_warren_rm_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren file deletion failed");
|
||||
}
|
||||
|
||||
async fn record_warren_entry_rename_success(&self) {
|
||||
async fn record_warren_mv_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren entry rename succeeded");
|
||||
}
|
||||
async fn record_warren_entry_rename_failure(&self) {
|
||||
async fn record_warren_mv_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren entry rename failed");
|
||||
}
|
||||
|
||||
async fn record_warren_save_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren file upload succeeded");
|
||||
}
|
||||
async fn record_warren_save_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren file upload failed");
|
||||
}
|
||||
|
||||
async fn record_warren_touch_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren entry touch succeeded");
|
||||
}
|
||||
async fn record_warren_touch_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren entry touch failed");
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSystemMetrics for MetricsDebugLogger {
|
||||
async fn record_list_files_success(&self) {
|
||||
tracing::debug!("[Metrics] File list succeeded");
|
||||
async fn record_ls_success(&self) {
|
||||
tracing::debug!("[Metrics] Ls succeeded");
|
||||
}
|
||||
async fn record_list_files_failure(&self) {
|
||||
tracing::debug!("[Metrics] File list failed");
|
||||
async fn record_ls_failure(&self) {
|
||||
tracing::debug!("[Metrics] Ls failed");
|
||||
}
|
||||
|
||||
async fn record_directory_creation_success(&self) {
|
||||
tracing::debug!("[Metrics] Directory creation succeeded");
|
||||
async fn record_cat_success(&self) {
|
||||
tracing::debug!("[Metrics] Cat succeeded");
|
||||
}
|
||||
async fn record_directory_creation_failure(&self) {
|
||||
tracing::debug!("[Metrics] Directory creation failed");
|
||||
async fn record_cat_failure(&self) {
|
||||
tracing::debug!("[Metrics] Cat failed");
|
||||
}
|
||||
|
||||
async fn record_directory_deletion_success(&self) {
|
||||
tracing::debug!("[Metrics] Directory deletion succeeded");
|
||||
async fn record_mkdir_success(&self) {
|
||||
tracing::debug!("[Metrics] Mkdir succeeded");
|
||||
}
|
||||
async fn record_directory_deletion_failure(&self) {
|
||||
tracing::debug!("[Metrics] Directory deletion failed");
|
||||
async fn record_mkdir_failure(&self) {
|
||||
tracing::debug!("[Metrics] Mkdir failed");
|
||||
}
|
||||
|
||||
async fn record_file_creation_success(&self) {
|
||||
tracing::debug!("[Metrics] File creation succeeded");
|
||||
async fn record_rm_success(&self) {
|
||||
tracing::debug!("[Metrics] Rm succeeded");
|
||||
}
|
||||
async fn record_file_creation_failure(&self) {
|
||||
tracing::debug!("[Metrics] File creation failed");
|
||||
async fn record_rm_failure(&self) {
|
||||
tracing::debug!("[Metrics] Rm failed");
|
||||
}
|
||||
|
||||
async fn record_file_fetch_success(&self) {
|
||||
tracing::debug!("[Metrics] File fetch succeeded");
|
||||
async fn record_mv_success(&self) {
|
||||
tracing::debug!("[Metrics] Mv succeeded");
|
||||
}
|
||||
async fn record_file_fetch_failure(&self) {
|
||||
tracing::debug!("[Metrics] File fetch failed");
|
||||
async fn record_mv_failure(&self) {
|
||||
tracing::debug!("[Metrics] Mv failed");
|
||||
}
|
||||
|
||||
async fn record_file_deletion_success(&self) {
|
||||
tracing::debug!("[Metrics] File deletion succeeded");
|
||||
async fn record_save_success(&self) {
|
||||
tracing::debug!("[Metrics] Save succeeded");
|
||||
}
|
||||
async fn record_file_deletion_failure(&self) {
|
||||
tracing::debug!("[Metrics] File deletion failed");
|
||||
async fn record_save_failure(&self) {
|
||||
tracing::debug!("[Metrics] Save failed");
|
||||
}
|
||||
|
||||
async fn record_entry_rename_success(&self) {
|
||||
tracing::debug!("[Metrics] Entry rename succeeded");
|
||||
async fn record_touch_success(&self) {
|
||||
tracing::debug!("[Metrics] Touch succeeded");
|
||||
}
|
||||
async fn record_entry_rename_failure(&self) {
|
||||
tracing::debug!("[Metrics] Entry rename failed");
|
||||
async fn record_touch_failure(&self) {
|
||||
tracing::debug!("[Metrics] Touch failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,13 +259,6 @@ impl AuthMetrics for MetricsDebugLogger {
|
||||
tracing::debug!("[Metrics] User warren deletion failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_fetch_file_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren file fetch succeeded");
|
||||
}
|
||||
async fn record_auth_warren_fetch_file_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren file fetch failed");
|
||||
}
|
||||
|
||||
async fn record_auth_fetch_user_warren_list_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren list succeeded");
|
||||
}
|
||||
@@ -297,45 +280,52 @@ impl AuthMetrics for MetricsDebugLogger {
|
||||
tracing::debug!("[Metrics] Auth warren fetch failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_file_list_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren file list succeeded");
|
||||
async fn record_auth_warren_ls_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren ls succeeded");
|
||||
}
|
||||
async fn record_auth_warren_file_list_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren file list failed");
|
||||
async fn record_auth_warren_ls_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren ls failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_directory_creation_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren directory creation succeeded");
|
||||
async fn record_auth_warren_cat_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren file fetch succeeded");
|
||||
}
|
||||
async fn record_auth_warren_directory_creation_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren directory creation failed");
|
||||
async fn record_auth_warren_cat_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren file fetch failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_directory_deletion_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren directory deletion succeeded");
|
||||
async fn record_auth_warren_mkdir_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren mkdir succeeded");
|
||||
}
|
||||
async fn record_auth_warren_directory_deletion_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren directory deletion failed");
|
||||
async fn record_auth_warren_mkdir_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren mkdir failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_file_deletion_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren file deletion succeeded");
|
||||
async fn record_auth_warren_rm_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren rm succeeded");
|
||||
}
|
||||
async fn record_auth_warren_file_deletion_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren file deletion failed");
|
||||
async fn record_auth_warren_rm_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren rm failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_entry_rename_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren entry rename succeeded");
|
||||
async fn record_auth_warren_mv_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren mv succeeded");
|
||||
}
|
||||
async fn record_auth_warren_entry_rename_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren entry rename failed");
|
||||
async fn record_auth_warren_mv_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren mv failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_files_upload_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren files upload succeeded");
|
||||
async fn record_auth_warren_save_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren save succeeded");
|
||||
}
|
||||
async fn record_auth_warren_files_upload_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren files upload failed");
|
||||
async fn record_auth_warren_save_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren save failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_touch_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren touch succeeded");
|
||||
}
|
||||
async fn record_auth_warren_touch_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren touch failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ use uuid::Uuid;
|
||||
use crate::domain::warren::{
|
||||
models::{
|
||||
auth_session::requests::FetchAuthSessionResponse,
|
||||
file::{AbsoluteFilePath, File, FilePath},
|
||||
file::{AbsoluteFilePath, File},
|
||||
user::{ListAllUsersAndWarrensResponse, LoginUserResponse, User},
|
||||
user_warren::UserWarren,
|
||||
warren::{
|
||||
CreateWarrenDirectoryResponse, DeleteWarrenDirectoryResponse, DeleteWarrenFileResponse,
|
||||
ListWarrenFilesResponse, RenameWarrenEntryResponse, UploadWarrenFilesResponse, Warren,
|
||||
Warren, WarrenLsResponse, WarrenMkdirResponse, WarrenMvResponse, WarrenRmResponse,
|
||||
WarrenSaveResponse, WarrenTouchResponse,
|
||||
},
|
||||
},
|
||||
ports::{AuthNotifier, FileSystemNotifier, WarrenNotifier},
|
||||
@@ -46,7 +46,7 @@ impl WarrenNotifier for NotifierDebugLogger {
|
||||
tracing::debug!("[Notifier] Fetched warren {}", warren.name());
|
||||
}
|
||||
|
||||
async fn warren_file_fetched(&self, warren: &Warren, path: &AbsoluteFilePath) {
|
||||
async fn warren_cat(&self, warren: &Warren, path: &AbsoluteFilePath) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Fetched file {} in warren {}",
|
||||
path,
|
||||
@@ -54,7 +54,7 @@ impl WarrenNotifier for NotifierDebugLogger {
|
||||
);
|
||||
}
|
||||
|
||||
async fn warren_files_listed(&self, response: &ListWarrenFilesResponse) {
|
||||
async fn warren_ls(&self, response: &WarrenLsResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Listed {} file(s) in warren {}",
|
||||
response.files().len(),
|
||||
@@ -62,7 +62,7 @@ impl WarrenNotifier for NotifierDebugLogger {
|
||||
);
|
||||
}
|
||||
|
||||
async fn warren_directory_created(&self, response: &CreateWarrenDirectoryResponse) {
|
||||
async fn warren_mkdir(&self, response: &WarrenMkdirResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Created directory {} in warren {}",
|
||||
response.path(),
|
||||
@@ -70,31 +70,11 @@ impl WarrenNotifier for NotifierDebugLogger {
|
||||
);
|
||||
}
|
||||
|
||||
async fn warren_directory_deleted(&self, response: &DeleteWarrenDirectoryResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Deleted directory {} in warren {}",
|
||||
response.path(),
|
||||
response.warren().name()
|
||||
);
|
||||
async fn warren_save(&self, warren: &Warren, path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Saved file {} to warren {}", path, warren.name());
|
||||
}
|
||||
|
||||
async fn warren_file_uploaded(&self, warren: &Warren, path: &FilePath) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Uploaded file {} to warren {}",
|
||||
path,
|
||||
warren.name()
|
||||
);
|
||||
}
|
||||
|
||||
async fn warren_files_uploaded(&self, response: &UploadWarrenFilesResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Uploaded {} file(s) to warren {}",
|
||||
response.paths().len(),
|
||||
response.warren().name()
|
||||
);
|
||||
}
|
||||
|
||||
async fn warren_file_deleted(&self, response: &DeleteWarrenFileResponse) {
|
||||
async fn warren_rm(&self, response: &WarrenRmResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Deleted file {} from warren {}",
|
||||
response.path(),
|
||||
@@ -102,7 +82,7 @@ impl WarrenNotifier for NotifierDebugLogger {
|
||||
);
|
||||
}
|
||||
|
||||
async fn warren_entry_renamed(&self, response: &RenameWarrenEntryResponse) {
|
||||
async fn warren_mv(&self, response: &WarrenMvResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Renamed file {} to {} in warren {}",
|
||||
response.old_path(),
|
||||
@@ -110,36 +90,44 @@ impl WarrenNotifier for NotifierDebugLogger {
|
||||
response.warren().name(),
|
||||
);
|
||||
}
|
||||
|
||||
async fn warren_touch(&self, warren: &Warren, path: &AbsoluteFilePath) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Touched file {} in warren {}",
|
||||
path,
|
||||
warren.name()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSystemNotifier for NotifierDebugLogger {
|
||||
async fn files_listed(&self, files: &Vec<File>) {
|
||||
async fn ls(&self, files: &Vec<File>) {
|
||||
tracing::debug!("[Notifier] Listed {} file(s)", files.len());
|
||||
}
|
||||
|
||||
async fn directory_created(&self, path: &FilePath) {
|
||||
tracing::debug!("[Notifier] Created directory {}", path);
|
||||
}
|
||||
|
||||
async fn directory_deleted(&self, path: &FilePath) {
|
||||
tracing::debug!("[Notifier] Deleted directory {}", path);
|
||||
}
|
||||
|
||||
async fn file_created(&self, path: &FilePath) {
|
||||
tracing::debug!("[Notifier] Created file {}", path);
|
||||
}
|
||||
|
||||
async fn file_fetched(&self, path: &AbsoluteFilePath) {
|
||||
async fn cat(&self, path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Fetched file {path}");
|
||||
}
|
||||
|
||||
async fn file_deleted(&self, path: &FilePath) {
|
||||
async fn mkdir(&self, path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Created directory {}", path);
|
||||
}
|
||||
|
||||
async fn rm(&self, path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Deleted file {}", path);
|
||||
}
|
||||
|
||||
async fn entry_renamed(&self, old_path: &FilePath, new_path: &FilePath) {
|
||||
async fn mv(&self, old_path: &AbsoluteFilePath, new_path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Renamed file {} to {}", old_path, new_path);
|
||||
}
|
||||
|
||||
async fn save(&self, path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Saved file {}", path);
|
||||
}
|
||||
|
||||
async fn touch(&self, path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Touched file {}", path);
|
||||
}
|
||||
}
|
||||
|
||||
impl AuthNotifier for NotifierDebugLogger {
|
||||
@@ -281,19 +269,14 @@ impl AuthNotifier for NotifierDebugLogger {
|
||||
);
|
||||
}
|
||||
|
||||
async fn auth_warren_file_fetched(
|
||||
&self,
|
||||
user: &User,
|
||||
warren_id: &Uuid,
|
||||
path: &AbsoluteFilePath,
|
||||
) {
|
||||
async fn auth_warren_cat(&self, user: &User, warren_id: &Uuid, path: &AbsoluteFilePath) {
|
||||
tracing::debug!(
|
||||
"[Notifier] User {} fetched file {path} in warren {warren_id}",
|
||||
user.id(),
|
||||
);
|
||||
}
|
||||
|
||||
async fn auth_warren_files_listed(&self, user: &User, response: &ListWarrenFilesResponse) {
|
||||
async fn auth_warren_ls(&self, user: &User, response: &WarrenLsResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Listed {} file(s) in warren {} for authenticated user {}",
|
||||
response.files().len(),
|
||||
@@ -302,11 +285,7 @@ impl AuthNotifier for NotifierDebugLogger {
|
||||
);
|
||||
}
|
||||
|
||||
async fn auth_warren_directory_created(
|
||||
&self,
|
||||
user: &User,
|
||||
response: &CreateWarrenDirectoryResponse,
|
||||
) {
|
||||
async fn auth_warren_mkdir(&self, user: &User, response: &WarrenMkdirResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Created directory {} in warren {} for authenticated user {}",
|
||||
response.path(),
|
||||
@@ -315,29 +294,16 @@ impl AuthNotifier for NotifierDebugLogger {
|
||||
);
|
||||
}
|
||||
|
||||
async fn auth_warren_directory_deleted(
|
||||
&self,
|
||||
user: &User,
|
||||
response: &DeleteWarrenDirectoryResponse,
|
||||
) {
|
||||
async fn auth_warren_save(&self, user: &User, response: &WarrenSaveResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Deleted directory {} in warren {} for authenticated user {}",
|
||||
"[Notifier] Uploaded file {} to warren {} for authenticated user {}",
|
||||
response.path(),
|
||||
response.warren().name(),
|
||||
user.id(),
|
||||
);
|
||||
}
|
||||
|
||||
async fn auth_warren_files_uploaded(&self, user: &User, response: &UploadWarrenFilesResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Uploaded {} file(s) to warren {} for authenticated user {}",
|
||||
response.paths().len(),
|
||||
response.warren().name(),
|
||||
user.id(),
|
||||
);
|
||||
}
|
||||
|
||||
async fn auth_warren_file_deleted(&self, user: &User, response: &DeleteWarrenFileResponse) {
|
||||
async fn auth_warren_rm(&self, user: &User, response: &WarrenRmResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Deleted file {} from warren {} for authenticated user {}",
|
||||
response.path(),
|
||||
@@ -346,7 +312,7 @@ impl AuthNotifier for NotifierDebugLogger {
|
||||
);
|
||||
}
|
||||
|
||||
async fn auth_warren_entry_renamed(&self, user: &User, response: &RenameWarrenEntryResponse) {
|
||||
async fn auth_warren_mv(&self, user: &User, response: &WarrenMvResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Renamed file {} to {} in warren {} for authenticated user {}",
|
||||
response.old_path(),
|
||||
@@ -355,4 +321,13 @@ impl AuthNotifier for NotifierDebugLogger {
|
||||
user.id(),
|
||||
);
|
||||
}
|
||||
|
||||
async fn auth_warren_touch(&self, user: &User, response: &WarrenTouchResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Touched file {} in warren {} for authenticated user {}",
|
||||
response.path(),
|
||||
response.warren().name(),
|
||||
user.id()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user