Skip to main content

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

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