backend refactor file_system into warren domain
This commit is contained in:
@@ -3,12 +3,12 @@ use std::time::UNIX_EPOCH;
|
||||
use anyhow::{Context, anyhow};
|
||||
use tokio::{fs, io::AsyncWriteExt as _};
|
||||
|
||||
use crate::domain::file_system::{
|
||||
use crate::domain::warren::{
|
||||
models::file::{
|
||||
AbsoluteFilePath, CreateDirectoryError, CreateDirectoryRequest, CreateFileError,
|
||||
CreateFileRequest, DeleteDirectoryError, DeleteDirectoryRequest, DeleteFileError,
|
||||
DeleteFileRequest, File, FileMimeType, FileName, FilePath, FileType, ListFilesError,
|
||||
ListFilesRequest,
|
||||
ListFilesRequest, RenameEntryError, RenameEntryRequest,
|
||||
},
|
||||
ports::FileSystemRepository,
|
||||
};
|
||||
@@ -139,6 +139,27 @@ impl FileSystem {
|
||||
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
async fn rename(
|
||||
&self,
|
||||
path: &AbsoluteFilePath,
|
||||
new_name: &FileName,
|
||||
) -> anyhow::Result<FilePath> {
|
||||
let current_path = self.get_target_path(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)?
|
||||
};
|
||||
|
||||
fs::rename(current_path, &new_path).await?;
|
||||
|
||||
Ok(new_path)
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSystemRepository for FileSystem {
|
||||
@@ -198,4 +219,20 @@ impl FileSystemRepository for FileSystem {
|
||||
|
||||
Ok(deleted_path)
|
||||
}
|
||||
|
||||
async fn rename_entry(
|
||||
&self,
|
||||
request: RenameEntryRequest,
|
||||
) -> Result<FilePath, RenameEntryError> {
|
||||
let new_path = self
|
||||
.rename(request.path(), request.new_name())
|
||||
.await
|
||||
.context(format!(
|
||||
"Failed to rename {} to {}",
|
||||
request.path(),
|
||||
request.new_name()
|
||||
))?;
|
||||
|
||||
Ok(new_path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::domain::{file_system::ports::FileSystemMetrics, warren::ports::WarrenMetrics};
|
||||
use crate::domain::warren::ports::{FileSystemMetrics, WarrenMetrics};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct MetricsDebugLogger;
|
||||
@@ -107,4 +107,11 @@ impl FileSystemMetrics for MetricsDebugLogger {
|
||||
async fn record_file_deletion_failure(&self) {
|
||||
log::debug!("[Metrics] File deletion failed");
|
||||
}
|
||||
|
||||
async fn record_entry_rename_success(&self) -> () {
|
||||
log::debug!("[Metrics] Entry rename succeeded");
|
||||
}
|
||||
async fn record_entry_rename_failure(&self) -> () {
|
||||
log::debug!("[Metrics] Entry rename failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::domain::{
|
||||
file_system::{
|
||||
models::file::{File, FilePath},
|
||||
ports::FileSystemNotifier,
|
||||
use crate::domain::warren::{
|
||||
models::{
|
||||
file::{File, FilePath},
|
||||
warren::Warren,
|
||||
},
|
||||
warren::{models::warren::Warren, ports::WarrenNotifier},
|
||||
ports::{FileSystemNotifier, WarrenNotifier},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -93,4 +93,8 @@ impl FileSystemNotifier for NotifierDebugLogger {
|
||||
async fn file_deleted(&self, path: &FilePath) {
|
||||
log::debug!("[Notifier] Deleted file {}", path);
|
||||
}
|
||||
|
||||
async fn entry_renamed(&self, old_path: &FilePath, new_path: &FilePath) {
|
||||
log::debug!("[Notifier] Renamed file {} to {}", old_path, new_path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user