~/bend-docscommunity

src/walk/disk.bend relies on unsafe/foreign

raw source on the hub · import 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/walk/disk.bend as Disk

walk/disk: an effect (CPU event loop only): the names directly in a directory, whether a path is a directory, and the working directory relative paths are named from. A name that is itself a directory ends in "/"; "." and ".." are never in the list, and a directory that cannot be opened lists as empty. Order is the file system's; the lint planner (src/lint/plan.bend) sorts what it keeps.

It is the real file system, through a foreign effect (dir.c, dir.js) that lists one directory: its names, one a line, a directory's name ending in "/"; one (cwd.c, cwd.js) that names the working directory; and Base's File, which tells a directory from a file.

1 import
import Base

Definitions

def named source · line 20 · raw

@ls:List<&2, String> -> List<&2, String>

the named lines: the text ends in a newline, so the last line is empty

def entries source · line 29 · raw

@dir:String -> IO(List<&2, String>)

a directory's entries, a directory marked by a /

def is_dir.code source · line 36 · raw

@rr:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> Bool

whether a first read failed as a directory's does (EISDIR, 21, in C and in node alike)

def is_dir.got source · line 45 · raw

@got:Pair(File, Result<&1, &1, Pair(U32, String), List<&2, U32>>) -> IO(Bool)

the file closed, and what its first read said

def is_dir.opened source · line 52 · raw

@rr:Result<&1, &1, Pair(U32, String), File> -> IO(Bool)

a path that opened: read one byte and see; one that did not is no directory

def is_dir source · line 64 · raw

@path:String -> IO(Bool)

whether a path is a directory: it opens, and reading it fails as a directory's read does. Base's File has no stat, and a directory opens for reading on both lanes.

def cwd source · line 75 · raw

IO(String)

the working directory, from the root ("" when it cannot be named)

Effects (foreign code)

effect walkdir.entries source · line 15 · raw

@dir:String -> IO(String)

every name directly in the directory, one a line

foreign: src/walk/dir.c, src/walk/dir.js

effect walkdir.cwd source · line 70 · raw

IO(String)

the working directory, from the root; "" when it cannot be named

foreign: src/walk/cwd.c, src/walk/cwd.js