Skip to main content

Mountain/IPC/WindServiceHandlers/FileSystem/Managed/
FileRead.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Legacy wire method `file:read` (UTF-8 content). Routes via RunTime's
4//! `FileSystemReader` trait. Not currently wired into dispatch (native
5//! variant handles `file:read`); kept for future per-provider routing.
6
7use std::{path::PathBuf, sync::Arc};
8
9use CommonLibrary::{Environment::Requires::Requires, FileSystem::FileSystemReader::FileSystemReader};
10use serde_json::{Value, json};
11
12use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
13
14pub async fn FileRead(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
15	let path = Arguments
16		.get(0)
17		.ok_or("Missing file path".to_string())?
18		.as_str()
19		.ok_or("File path must be a string".to_string())?;
20
21	let provider:Arc<dyn FileSystemReader> = RunTime.Environment.Require();
22
23	let content = provider
24		.ReadFile(&PathBuf::from(path))
25		.await
26		.map_err(|Error| format!("Failed to read file: {}", Error))?;
27
28	dev_log!("vfs-verbose", "read: {} ({} bytes)", path, content.len());
29	Ok(json!(content))
30}