Mountain/IPC/WindServiceHandlers/FileSystem/Managed/
FileMove.rs1use std::{path::PathBuf, sync::Arc};
4
5use CommonLibrary::{
6 Environment::Requires::Requires,
7 Error::CommonError::CommonError,
8 FileSystem::FileSystemWriter::FileSystemWriter,
9};
10use serde_json::Value;
11
12use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
13
14pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
15 let source = Arguments
16 .get(0)
17 .ok_or("Missing source path".to_string())?
18 .as_str()
19 .ok_or("Source path must be a string".to_string())?;
20
21 let destination = Arguments
22 .get(1)
23 .ok_or("Missing destination path".to_string())?
24 .as_str()
25 .ok_or("Destination path must be a string".to_string())?;
26
27 let provider:Arc<dyn FileSystemWriter> = RunTime.Environment.Require();
28
29 provider
30 .Rename(&PathBuf::from(source), &PathBuf::from(destination), false)
31 .await
32 .map_err(|e:CommonError| format!("Failed to move file: {} -> {}", source, destination))?;
33
34 dev_log!("vfs-verbose", "moved: {} -> {}", source, destination);
35
36 Ok(Value::Null)
37}