Skip to main content

Mountain/IPC/WindServiceHandlers/FileSystem/Managed/
FileMove.rs

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