MCPcopy Create free account
hub / github.com/openai/plugins / open_read_fd

Function open_read_fd

plugins/codex-security/scripts/windows_scan_local_files.py:434–465  ·  view source on GitHub ↗

Open a verified regular file and return an owned binary read descriptor.

(scan_dir: Path, relative_path: str, context: str)

Source from the content-addressed store, hash-verified

432
433
434def open_read_fd(scan_dir: Path, relative_path: str, context: str) -> int:
435 """Open a verified regular file and return an owned binary read descriptor."""
436
437 try:
438 with _locked_parent(scan_dir, relative_path, create=False) as (parent_path, leaf_name):
439 path = parent_path / leaf_name
440 handle = _create_file(
441 path,
442 access=_GENERIC_READ | _FILE_READ_ATTRIBUTES,
443 # Denying write/delete sharing keeps the opened contents stable.
444 share=_FILE_SHARE_READ,
445 disposition=_OPEN_EXISTING,
446 flags=_FILE_FLAG_OPEN_REPARSE_POINT,
447 )
448 assert handle is not None and handle.value is not None
449 try:
450 _verify_regular_file(handle.value, path)
451 raw_handle = handle.detach()
452 try:
453 assert _msvcrt is not None
454 return _msvcrt.open_osfhandle(raw_handle, os.O_RDONLY | os.O_BINARY)
455 except BaseException:
456 _close_handle(raw_handle)
457 raise
458 finally:
459 handle.close()
460 except WindowsScanLocalFileError as exc:
461 raise WindowsScanLocalFileError(
462 exc.errno,
463 f"{context}: {exc.strerror}",
464 exc.filename,
465 ) from exc
466
467
468def _write_all(handle: int, payload: bytes) -> None:

Callers

nothing calls this directly

Calls 7

_locked_parentFunction · 0.85
_create_fileFunction · 0.85
_verify_regular_fileFunction · 0.85
_close_handleFunction · 0.85
detachMethod · 0.80
closeMethod · 0.65

Tested by

no test coverage detected