Skip to main content

Mountain/IPC/WindServiceHandlers/FileSystem/Native/
FileStatNative.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Wire method `file:stat`. Returns VS Code's `IStat` shape via
4//! `metadata_to_istat`. Uses `symlink_metadata` to avoid following
5//! symlinks (matches Electron behaviour). Noise from benign ENOENTs on
6//! known VS Code probe paths is squelched via `IsBenignEnoent` +
7//! `DebugOnce`.
8
9use serde_json::Value;
10
11use crate::{
12	IPC::{
13		DevLog,
14		WindServiceHandlers::Utilities::{MetadataEncoding::metadata_to_istat, PathExtraction::extract_path_from_arg},
15	},
16	dev_log,
17};
18
19pub async fn FileStatNative(Arguments:Vec<Value>) -> Result<Value, String> {
20	let Path = extract_path_from_arg(Arguments.get(0).ok_or("Missing file path")?)?;
21
22	// Per-path stat emits at very high volume during workbench boot
23	// (package.json / launch.json / settings.json probes from every
24	// extension). Gate to `vfs-verbose`; the ENOENT path retains the
25	// `vfs` tag so real misses still surface at the default level.
26	if !DevLog::IsBenignEnoent::Fn(&Path) {
27		dev_log!("vfs-verbose", "stat: {}", Path);
28	}
29
30	let Metadata = tokio::fs::symlink_metadata(&Path).await.map_err(|E| {
31		if DevLog::IsBenignEnoent::Fn(&Path) {
32			DevLog::DebugOnce::Fn(
33				"vfs",
34				&format!("stat-enoent:{}", Path),
35				&format!("stat ENOENT (benign): {}", Path),
36			);
37		} else {
38			dev_log!("vfs", "stat ENOENT: {}", Path);
39		}
40		format!("Failed to stat file: {} (path: {})", E, Path)
41	})?;
42
43	if !DevLog::IsBenignEnoent::Fn(&Path) {
44		dev_log!("vfs-verbose", "stat OK: {} (dir={})", Path, Metadata.is_dir());
45	}
46	Ok(metadata_to_istat(&Metadata))
47}