import { PathSpec } from '../../../types.ts'; import type { CommandOpts } from '../../config.ts'; import type { LinkView, MountView } from '../../../ops/types.ts'; export type DuEntries = [entries: [string, number][], total: number]; export type ComputeSize = (p: PathSpec) => Promise; export type ComputeEntries = (p: PathSpec) => Promise; export declare const DEFAULT_MAX_DU_ENTRIES = 10000; /** * Read a `--max-depth` value the way GNU's `xstrtoul` does. * * That is C `strtoul` with base 0: a `0x` prefix is hexadecimal, a bare * leading `0` is octal (so `010` is 8 and `09` is invalid), anything else is * decimal. Surrounding whitespace is not allowed. */ export declare function parseDepth(text: string): number | null; /** The parsed `du` command line. */ export interface DuFlags { /** -s, one total per operand and no subtree lines. */ s: boolean; /** -a, list files as well as directories. */ a: boolean; /** -h, human-readable sizes. */ h: boolean; /** -c, append a grand total. */ c: boolean; /** -S/--separate-dirs, directories exclude subdirectory sizes. */ S: boolean; /** --max-depth/-d, deepest level to print. */ maxDepth: number | null; /** A non-fatal diagnostic GNU prints before the output. */ warning?: string; } /** What `du` produced for one invocation. */ export interface DuOutput { stdout: Uint8Array; /** Diagnostics: unreadable operands, then the truncation notice. */ stderr: Uint8Array; /** * 0, or 1 when an operand could not be read or a walk was cut short, as GNU * does for a tree it could not fully account for. */ exitCode: number; } /** * Validate a `du` command line the way GNU does, before any I/O. * * GNU parses `--max-depth` as each option is read, so a bad depth is reported * ahead of the mutually-exclusive checks that run once the whole line is * parsed. All three exit 1, du's usage-error code. */ export declare function parseFlags(opts: CommandOpts): DuFlags; /** * Lift mount-relative walk entries onto absolute virtual paths. * * Backends walk their own key space and report mount-relative paths, so two * mounts that both hold `notes.txt` would otherwise render the same line. The * mount prefix is recovered from the operand the same way `find` and `grep -r` * recover it. */ export declare function toVirtual(entries: [string, number][], path: PathSpec): [string, number][]; /** * Sum of leaves whose parent is the operand (GNU `-S` total). */ export declare function separateTotal(entries: [string, number][], root: string): number; /** * Derive GNU's per-directory lines from a flat list of leaf files. * * Backends report only files, but GNU `du` prints a line per directory * carrying its recursive total (and, under `-a`, a line per file too). Every * directory between the operand and a leaf therefore accumulates that leaf's * size, and the result is emitted post-order: children before their parent, * siblings sorted by name. GNU walks in readdir order, which is unspecified, * so sorting is a deterministic choice within the same shape. * * With `-S`/`--separate-dirs` a directory only counts files that sit * directly in it: a leaf still forces every ancestor directory to appear * (possibly at size 0), but only the immediate parent gets its bytes. * The operand's own line is not included; the caller renders it with the * operand as typed. */ export declare function rollup(entries: [string, number][], root: string, opts: { all: boolean; maxDepth: number | null; dirs?: readonly string[]; separateDirs?: boolean; }): [string, number][]; /** * Run one whole `du` invocation, from raw flags to rendered bytes. * * Every caller needs the same three steps in the same order: validate the * flags before touching I/O, split the operands into readable and unreadable, * then render. Keeping them here means a backend wrapper is wiring only, and * the three steps cannot drift apart per backend. */ export declare function runDu(paths: PathSpec[], opts: CommandOpts, resolveGlob: (targets: PathSpec[]) => Promise, stat: (p: PathSpec) => Promise, computeSize: ComputeSize, computeEntries: ComputeEntries, truncated?: () => boolean, unreadable?: () => readonly string[]): Promise; /** * Render `du` output for a list of operands. * * `computeEntries` reports mount-relative (path, size) pairs plus the total; * pass `undefined` on backends that can only produce a size, which makes both * `-a` and the per-directory lines degrade to one total. `missing` names the * operands that could not be read: GNU reports each and exits 1 but still * prints the rest. `truncated` is read after the walks to ask whether any of * them hit its entry cap. `mounts` marks the descendant boundaries: leaves * under one are shadowed and dropped from every row and total (see * `dropShadowed`). `unreadable` is read after the walks for the directories a * walk could not open (a rule refused them below the operand): GNU names each * one, counts what it could, and exits 1; the line is spelled as the operand * was typed, and follows the unreadable-operand lines since those are known * before any walk. */ export declare function duGeneric(paths: PathSpec[], flags: DuFlags, computeSize: ComputeSize, computeEntries: ComputeEntries, missing?: [string, string][], truncated?: () => boolean, links?: LinkView | null, mounts?: MountView | null, unreadable?: () => readonly string[]): Promise; //# sourceMappingURL=du.d.ts.map