Skip to main content

Mountain/IPC/WindServiceHandlers/Model/
TextfileSave.rs

1
2//! Save-intent hint from Wind. Actual disk write happens via `TextfileWrite`.
3//! Returns an `IStat`-shaped object (mtime/size) so the workbench's
4//! `TextFileEditorModel` can update its etag cache and clear the dirty dot
5//! without a spurious "file changed on disk" conflict on the next read.
6
7use std::sync::Arc;
8
9use serde_json::Value;
10
11use crate::{
12	IPC::WindServiceHandlers::Utilities::{
13		MetadataEncoding::Fn as metadata_to_istat,
14		PathExtraction::Fn as extract_path_from_arg,
15	},
16	RunTime::ApplicationRunTime::ApplicationRunTime,
17	dev_log,
18};
19
20pub async fn Fn(_runtime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
21	let ResourceArg = Arguments.first().ok_or("textFile:save requires a resource argument")?;
22
23	let Path = extract_path_from_arg(ResourceArg).unwrap_or_default();
24
25	dev_log!("vfs", "textFile:save path={:?}", Path);
26
27	if Path.is_empty() {
28		return Ok(Value::Null);
29	}
30
31	match tokio::fs::metadata(&Path).await {
32		Ok(Meta) => Ok(metadata_to_istat(&Meta)),
33
34		Err(_) => Ok(Value::Null),
35	}
36}