copy files
This commit is contained in:
@@ -14,10 +14,10 @@ use crate::{
|
||||
domain::warren::{
|
||||
models::{
|
||||
file::{
|
||||
AbsoluteFilePath, CatError, CatRequest, File, FileMimeType, FileName, FilePath,
|
||||
FileStream, FileType, LsError, LsRequest, LsResponse, MkdirError, MkdirRequest,
|
||||
MvError, MvRequest, RelativeFilePath, RmError, RmRequest, SaveError, SaveRequest,
|
||||
SaveResponse, TouchError, TouchRequest,
|
||||
AbsoluteFilePath, CatError, CatRequest, CpError, CpRequest, CpResponse, File,
|
||||
FileMimeType, FileName, FilePath, FileStream, FileType, LsError, LsRequest,
|
||||
LsResponse, MkdirError, MkdirRequest, MvError, MvRequest, RelativeFilePath,
|
||||
RmError, RmRequest, SaveError, SaveRequest, SaveResponse, TouchError, TouchRequest,
|
||||
},
|
||||
warren::UploadFileStream,
|
||||
},
|
||||
@@ -242,7 +242,20 @@ impl FileSystem {
|
||||
async fn touch(&self, path: &AbsoluteFilePath) -> io::Result<()> {
|
||||
let path = self.get_target_path(path);
|
||||
|
||||
tokio::fs::File::create(&path).await.map(|_| ())
|
||||
fs::File::create(&path).await.map(|_| ())
|
||||
}
|
||||
|
||||
async fn cp(
|
||||
&self,
|
||||
path: AbsoluteFilePath,
|
||||
target_path: AbsoluteFilePath,
|
||||
) -> io::Result<CpResponse> {
|
||||
let fs_current_path = self.get_target_path(&path);
|
||||
let fs_target_path = self.get_target_path(&target_path);
|
||||
|
||||
fs::copy(fs_current_path, fs_target_path).await?;
|
||||
|
||||
Ok(CpResponse::new(path, target_path))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,6 +326,13 @@ impl FileSystemRepository for FileSystem {
|
||||
let (path, mut stream) = request.unpack();
|
||||
Ok(self.save(&path, &mut stream).await.map(SaveResponse::new)?)
|
||||
}
|
||||
|
||||
async fn cp(&self, request: CpRequest) -> Result<CpResponse, CpError> {
|
||||
let (path, target_path) = request.into_paths();
|
||||
self.cp(path, target_path)
|
||||
.await
|
||||
.map_err(|e| CpError::Unknown(e.into()))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Use `DirEntry::metadata` once `target=x86_64-unknown-linux-musl` updates from musl 1.2.3 to 1.2.5
|
||||
|
||||
@@ -100,6 +100,13 @@ impl WarrenMetrics for MetricsDebugLogger {
|
||||
async fn record_warren_touch_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren entry touch failed");
|
||||
}
|
||||
|
||||
async fn record_warren_cp_success(&self) {
|
||||
tracing::debug!("[Metrics] Warren entry cp succeeded");
|
||||
}
|
||||
async fn record_warren_cp_failure(&self) {
|
||||
tracing::debug!("[Metrics] Warren entry cp failed");
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSystemMetrics for MetricsDebugLogger {
|
||||
@@ -151,6 +158,13 @@ impl FileSystemMetrics for MetricsDebugLogger {
|
||||
async fn record_touch_failure(&self) {
|
||||
tracing::debug!("[Metrics] Touch failed");
|
||||
}
|
||||
|
||||
async fn record_cp_success(&self) {
|
||||
tracing::debug!("[Metrics] Cp succeeded");
|
||||
}
|
||||
async fn record_cp_failure(&self) {
|
||||
tracing::debug!("[Metrics] Cp failed");
|
||||
}
|
||||
}
|
||||
|
||||
impl AuthMetrics for MetricsDebugLogger {
|
||||
@@ -328,4 +342,11 @@ impl AuthMetrics for MetricsDebugLogger {
|
||||
async fn record_auth_warren_touch_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren touch failed");
|
||||
}
|
||||
|
||||
async fn record_auth_warren_cp_success(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren cp succeeded");
|
||||
}
|
||||
async fn record_auth_warren_cp_failure(&self) {
|
||||
tracing::debug!("[Metrics] Auth warren cp failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ use crate::domain::warren::{
|
||||
user::{ListAllUsersAndWarrensResponse, LoginUserResponse, User},
|
||||
user_warren::UserWarren,
|
||||
warren::{
|
||||
Warren, WarrenLsResponse, WarrenMkdirResponse, WarrenMvResponse, WarrenRmResponse,
|
||||
WarrenSaveResponse, WarrenTouchResponse,
|
||||
Warren, WarrenCpResponse, WarrenLsResponse, WarrenMkdirResponse, WarrenMvResponse,
|
||||
WarrenRmResponse, WarrenSaveResponse, WarrenTouchResponse,
|
||||
},
|
||||
},
|
||||
ports::{AuthNotifier, FileSystemNotifier, WarrenNotifier},
|
||||
@@ -98,6 +98,15 @@ impl WarrenNotifier for NotifierDebugLogger {
|
||||
warren.name()
|
||||
);
|
||||
}
|
||||
|
||||
async fn warren_cp(&self, response: &WarrenCpResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Copied file {} to {} in warren {}",
|
||||
response.base().path(),
|
||||
response.base().target_path(),
|
||||
response.warren().name()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSystemNotifier for NotifierDebugLogger {
|
||||
@@ -128,6 +137,10 @@ impl FileSystemNotifier for NotifierDebugLogger {
|
||||
async fn touch(&self, path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Touched file {}", path);
|
||||
}
|
||||
|
||||
async fn cp(&self, path: &AbsoluteFilePath, target_path: &AbsoluteFilePath) {
|
||||
tracing::debug!("[Notifier] Copied file {} to {}", path, target_path);
|
||||
}
|
||||
}
|
||||
|
||||
impl AuthNotifier for NotifierDebugLogger {
|
||||
@@ -330,4 +343,14 @@ impl AuthNotifier for NotifierDebugLogger {
|
||||
user.id()
|
||||
)
|
||||
}
|
||||
|
||||
async fn auth_warren_cp(&self, user: &User, response: &WarrenCpResponse) {
|
||||
tracing::debug!(
|
||||
"[Notifier] Copied file {} to {} in warren {} for authenticated user {}",
|
||||
response.base().path(),
|
||||
response.base().target_path(),
|
||||
response.warren().name(),
|
||||
user.id()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user