Skip to main content

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

1//! Wire method `file:exists`. Boolean probe via `tokio::fs::try_exists`.
2
3use serde_json::{Value, json};
4
5use crate::IPC::WindServiceHandlers::Utilities::PathExtraction::Fn as extract_path_from_arg;
6
7pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
8	let Path = extract_path_from_arg(Arguments.get(0).ok_or("Missing file path")?)?;
9
10	// Propagate I/O errors (permission denied, broken symlink) rather than
11	// returning false. unwrap_or(false) would make errors look like "not found",
12	// causing VS Code to overwrite existing files it cannot read.
13	let Exists = tokio::fs::try_exists(&Path)
14		.await
15		.map_err(|E| format!("file:exists I/O error for {}: {}", Path, E))?;
16
17	Ok(json!(Exists))
18}