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