import { FlagView } from '../../spec/flag_view.ts';
import { LineFacts, PathSpec } from '../../../types.ts';
import type { Context } from '../../config.ts';
import { IOResult, type PathRecord } from '../../../io/types.ts';
import type { MountView } from '../../../view/types.ts';
export type ComputeSize = (p: PathSpec) => Promise<number>;
export type DuEntries = [entries: [string, number][], total: number];
export type ComputeEntries = (p: PathSpec) => Promise<DuEntries>;
/** 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;
    /**
     * Each readable operand's measurement; null when one was only summed (`-s`,
     * or a backend that can only produce a size).
     */
    records: PathRecord[] | null;
}
/**
 * du's options, `--max-depth` and its conflicts with `-s` and `-a` read by
 * mirage-rs before any operand is resolved: the flags, or du's refusal.
 * Mirrors Python's `parse_flags`.
 */
export declare function parseFlags(ctx: Context): DuFlags | IOResult;
/**
 * 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, ctx: {
    all: boolean;
    maxDepth: number | null;
    dirs?: readonly string[];
    separateDirs?: boolean;
}): [string, number][];
/** Each file a measurement counted, as (virtual path, bytes). */
export declare function leavesOf(records: readonly PathRecord[]): [string, number][];
/**
 * Render `du` output for a list of operands.
 *
 * `computeEntries` reports mount-relative (path, size) pairs plus the total.
 * `missing` names the operands that could not be read: GNU reports each and
 * exits 1 but still prints the rest. `stopped` is read after the walks for
 * where one ran past `walkLimit`, each line without the command's name.
 * `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. `directories` is read after each operand's
 * walk for every directory it met, so one no file points at (empty, or
 * refused) still gets GNU's row. `inaccessible` is read after the walks for
 * each link `-L` could not follow, with the strerror GNU adds for a chain
 * that loops (it names a dangling one alone); exits 1.
 */
export declare function du(paths: PathSpec[], flags: DuFlags, computeSize: ComputeSize, computeEntries: ComputeEntries, missing?: [string, string][], stopped?: () => readonly string[], mounts?: MountView | null, unreadable?: () => readonly string[], directories?: () => readonly string[], inaccessible?: () => readonly (readonly [string, string | null])[], repeated?: (p: PathSpec) => boolean): Promise<DuOutput>;
/**
 * 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.
 *
 * The walks meet links as entries of their own; under -L they follow them
 * instead, which the operand's own was already, at dispatch. Deliberate
 * divergence: a link counts as its target string's length, the size `ls -l`
 * prints, where GNU counts the disk blocks it holds (0 for a target short
 * enough to live in the inode); mirage counts bytes throughout.
 */
export declare function duGeneric(paths: PathSpec[], ctx: Context, resolveGlob: (targets: PathSpec[]) => Promise<PathSpec[]>, stat: (p: PathSpec) => Promise<unknown>, computeSize: ComputeSize, computeEntries: ComputeEntries, stopped?: () => readonly string[], unreadable?: () => readonly string[], directories?: () => readonly string[], inaccessible?: () => readonly (readonly [string, string | null])[], repeated?: (p: PathSpec) => boolean): Promise<[Uint8Array, IOResult]>;
/**
 * A du line reads below every path it names, walks into the mounts below
 * unless `-x`, and follows a link operand when the last of `-L` and `-P` is
 * `-L`. Mirrors Python's `facts`.
 */
export declare function facts(fl: FlagView, _operands: readonly (string | PathSpec)[]): LineFacts;
//# sourceMappingURL=du.d.ts.map