Mountain/IPC/WindServiceHandlers/FileSystem/Native/
FileRenameNative.rs1use serde_json::{Value, json};
4
5use crate::{IPC::WindServiceHandlers::Utilities::PathExtraction::Fn as extract_path_from_arg, dev_log};
6
7pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
8 let Source = extract_path_from_arg(Arguments.get(0).ok_or("Missing source path")?)?;
9
10 let Target = extract_path_from_arg(Arguments.get(1).ok_or("Missing target path")?)?;
11
12 tokio::fs::rename(&Source, &Target)
13 .await
14 .map_err(|E| format!("Failed to rename: {} -> {} ({})", Source, Target, E))?;
15
16 let OldUri = format!("file://{}", Source);
18
19 let NewUri = format!("file://{}", Target);
20
21 dev_log!("vfs", "file:rename ok {} -> {}", Source, Target);
22
23 tokio::spawn(async move {
24 if let Err(Error) = crate::Vine::Client::SendNotification::Fn(
25 "cocoon-main".to_string(),
26 "$acceptDidRenameFiles".to_string(),
27 json!({ "files": [{ "oldUri": OldUri, "newUri": NewUri }] }),
28 )
29 .await
30 {
31 dev_log!(
32 "vfs",
33 "warn: [FileRenameNative] $acceptDidRenameFiles notify failed: {:?}",
34 Error
35 );
36 }
37 });
38
39 Ok(Value::Null)
40}