Skip to main content

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

1//! `file:close` - close an fd returned by `file:open` and free the entry.
2//!
3//! Arguments\[0\] = integer fd (as returned by FileOpenFd).
4//! Silently ignores unknown fds (VS Code may call close on an already-
5//! closed fd during workbench teardown).
6
7use serde_json::Value;
8
9use crate::{
10	IPC::WindServiceHandlers::{FileSystem::Native::FileOpenFd::GetFdTable, Utilities::JsonValueHelpers::arg_u64},
11	dev_log,
12};
13
14pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
15	let Fd = arg_u64(&Arguments, 0) as u32;
16
17	if Fd == 0 {
18		return Ok(Value::Null);
19	}
20
21	if let Ok(mut Table) = GetFdTable().Files.lock() {
22		let Removed = Table.remove(&Fd).is_some();
23
24		dev_log!("vfs", "file:close fd={} removed={}", Fd, Removed);
25	}
26
27	Ok(Value::Null)
28}