Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Model/
TextfileSave.rs

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