compiler_filesystem.l0

compiler_filesystem.l0

Module: compiler_filesystem

Source: compiler/stage2_l0/src/compiler_filesystem.l0 Language: Dea/L0

Imports / Includes

  • util.diag
  • std.time
  • std.vector
  • std.text
  • std.system
  • std.string
  • std.array
  • sys.rt

Symbols

Variable CFS_PATH_ABSENT

1
let CFS_PATH_ABSENT: int = 0

No filesystem object exists at the path.

Variable CFS_PATH_REGULAR

1
let CFS_PATH_REGULAR: int = 1

A regular file exists at the path.

Variable CFS_PATH_DIRECTORY

1
let CFS_PATH_DIRECTORY: int = 2

A directory exists at the path.

Variable CFS_PATH_OTHER

1
let CFS_PATH_OTHER: int = 3

A symlink, reparse point, or other unsupported object exists at the path.

Function l0c_fs_mkdir

1
extern func l0c_fs_mkdir(path: byte*, path_len: int, mode: int) -> int

Create one directory from a native path byte span.

Parameters:

  • path: Non-empty native path bytes without an embedded NUL.
  • path_len: Number of bytes in path.
  • mode: POSIX permission and special bits through 07777; validated but otherwise ignored on Windows.

Returns: 1 after creation, 0 when an object already exists at the path, or -1 on invalid input or an operating-system error.

Function l0c_fs_join_child

1
extern func l0c_fs_join_child(parent: byte*, parent_len: int, child: byte*, child_len: int, output: byte*?, output_capacity: int) -> int

Join a trusted parent path and one internal child name.

A query with a null output and zero capacity returns the required byte length. A sufficiently large output span receives the path without a trailing NUL.

Parameters:

  • parent: Non-empty native parent path bytes without an embedded NUL.
  • parent_len: Number of bytes in parent.
  • child: Non-empty native child-name bytes without an embedded NUL.
  • child_len: Number of bytes in child.
  • output: Optional destination for the joined path bytes.
  • output_capacity: Available bytes in output, or zero for a query.

Returns: Required byte length, or -1 on invalid input or overflow.

Function l0c_fs_path_kind_nofollow

1
extern func l0c_fs_path_kind_nofollow(path: byte*, path_len: int) -> int

Classify one native path without following a final symlink or reparse point.

Parameters:

  • path: Non-empty native path bytes without an embedded NUL.
  • path_len: Number of bytes in path.

Returns: A CFS_PATH_* kind, or -1 on invalid input or an operating-system error.

Function l0c_fs_path_kind_follow

1
extern func l0c_fs_path_kind_follow(path: byte*, path_len: int) -> int

Classify one native path after following symlinks or reparse points.

Parameters:

  • path: Non-empty native path bytes without an embedded NUL.
  • path_len: Number of bytes in path.

Returns: A CFS_PATH_* kind, with dangling links reported as absent, or -1 on invalid input or an operating-system error.

Function l0c_fs_remove_regular_file

1
extern func l0c_fs_remove_regular_file(path: byte*, path_len: int) -> int

Remove one regular file without following a substituted path object.

Parameters:

  • path: Non-empty native path bytes without an embedded NUL.
  • path_len: Number of bytes in path.

Returns: 1 after removal, 0 when absent, or -1 for invalid input, an unsupported object kind, or an operating-system error.

Function l0c_fs_remove_empty_dir

1
extern func l0c_fs_remove_empty_dir(path: byte*, path_len: int) -> int

Remove one empty real directory without accepting a symlink or reparse point.

Parameters:

  • path: Non-empty native path bytes without an embedded NUL.
  • path_len: Number of bytes in path.

Returns: 1 after removal, 0 when absent, or -1 on invalid input, a non-directory object, a non-empty directory, or an operating-system error.

Function l0c_fs_resolve_trusted_temp_parent

1
extern func l0c_fs_resolve_trusted_temp_parent(path: byte*, path_len: int, output: byte*?, output_capacity: int) -> int

Resolve and validate one selected compiler temporary parent.

A query with a null output and zero capacity returns the canonical byte length. A sufficiently large output span receives the canonical path without a trailing NUL. POSIX validates the complete resolved directory trust chain; Windows relies on the documented trusted-parent ACL assumption.

Parameters:

  • path: Non-empty native path bytes without an embedded NUL.
  • path_len: Number of bytes in path.
  • output: Optional destination for the canonical path bytes.
  • output_capacity: Available bytes in output, or zero for a query.

Returns: Canonical byte length, or -1 on invalid input, trust failure, or an operating-system error.

Function cfs_error

1
func cfs_error(diags: DiagCollector*, code: string, message: string, path: string)

Emit one compiler-filesystem diagnostic without source coordinates.

Function cfs_path_kind

1
func cfs_path_kind(path: string) -> int

Call the compiler-internal no-follow path classifier.

Function cfs_path_kind_follow

1
func cfs_path_kind_follow(path: string) -> int

Call the compiler-internal follow path classifier.

Function cfs_join_child

1
func cfs_join_child(parent: string, child: string) -> string

Join a trusted parent and internal child using actual-host separators.

Function cfs_mkdir

1
func cfs_mkdir(path: string, mode: int) -> int

Create one directory using the compiler-internal raw-byte ABI.

Function cfs_remove_regular_file

1
func cfs_remove_regular_file(path: string) -> int

Remove one regular file without following a substituted path.

Function cfs_remove_empty_dir

1
func cfs_remove_empty_dir(path: string) -> int

Remove one empty real directory through the compiler-internal ABI.

Function cfs_resolve_trusted_temp_parent

1
func cfs_resolve_trusted_temp_parent(path: string) -> string?

Resolve and validate one selected temporary parent.

The support ABI determines the actual host. POSIX validates the complete resolved owner/sticky-bit chain; Windows retains the trusted-parent ACL assumption. Platform-alias environment variables are deliberately ignored.

Parameters:

  • path: Selected existing directory.

Returns: Canonical trusted path, or null on failure.

Function cfs_select_temp_parent_from_values

1
func cfs_select_temp_parent_from_values(tmpdir: string?, temp: string?, tmp: string?, system_tmp: string, fallback: string, diags: DiagCollector*) -> string?

Select a temporary parent from explicit candidate values.

Empty values, absent paths, and non-directories fall through. Inspection errors are fatal; once a directory is selected, canonical resolution and trust validation are also authoritative.

The explicit system_tmp and fallback parameters are an internal test seam. Production supplies /tmp and . respectively.

Function cfs_select_temp_parent

1
func cfs_select_temp_parent(diags: DiagCollector*) -> string?

Return the first existing temporary-parent directory by stable precedence.

Function cfs_workspace_free

1
func cfs_workspace_free(self: CompilerWorkspace*)

Release a workspace path bundle after explicit cleanup.

Function cfs_workspace_child

1
func cfs_workspace_child(workspace: CompilerWorkspace*, leaf: string) -> string

Register and return one fixed driver-selected workspace child.

Parameters:

  • workspace: Workspace that owns the child.
  • leaf: Fixed child filename.

Returns: Joined child path.

Function cfs_workspace_create_for_identity

1
func cfs_workspace_create_for_identity(parent_path: string, tag: string, pid: int, sec: int, nsec: int, diags: DiagCollector*) -> CompilerWorkspace*?

Exclusively reserve one workspace from a deterministic identity tuple.

Pre-existing candidates are skipped and no unchecked fallback is returned.

Function cfs_workspace_create

1
func cfs_workspace_create(tag: string, diags: DiagCollector*) -> CompilerWorkspace*?

Select, resolve, validate, and exclusively reserve one compiler workspace.

Function cfs_workspace_cleanup

1
func cfs_workspace_cleanup(workspace: CompilerWorkspace*, diags: DiagCollector*) -> bool

Remove only known regular children, then the empty owned directory.

Cleanup first verifies the workspace root without following aliases. An unexpected child or substituted path retains the workspace for inspection.

Function cfs_apply_cleanup_status

1
func cfs_apply_cleanup_status(primary_status: int, cleanup_ok: bool) -> int

Apply cleanup failure to a command’s already-determined status.

Cleanup turns success into status 1, while an existing failure or program status remains authoritative.

Struct CompilerWorkspace

Invocation-owned native build/run workspace.

CompilerWorkspace Field root

1
root: string

CompilerWorkspace Field children

1
children: StringVector*