Files
bare-operating-system/kernel/bin/find
T
Raven Scott 21325e18d3
Release rolling / release (push) Successful in 9m45s
Harden Coreutils Bump to 0.1.1
2026-08-12 21:47:16 -04:00

820 lines
23 KiB
Plaintext

/* BARE_OS_BIN_API 1.0.0 — bump when staged /bin script semantics change (see developer guide). */
/** Shared helpers for drive-resident /bin scripts (prepended before each command). */
function bareStdin(ctx) {
return typeof ctx.shellStdin === 'string' ? ctx.shellStdin : ''
}
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
function bareFormatModeString(mode, type) {
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
const perm = mode & 0o777
const r = (bit) => (perm & bit ? 'r' : '-')
const w = (bit) => (perm & bit ? 'w' : '-')
const x = (bit) => (perm & bit ? 'x' : '-')
return (
typeChar +
r(0o400) +
w(0o200) +
x(0o100) +
r(0o040) +
w(0o020) +
x(0o010) +
r(0o004) +
w(0o002) +
x(0o001)
)
}
/** @param {number} mtimeMs @param {number} [nowMs] */
function bareFormatLsMtime(mtimeMs, nowMs) {
const now = nowMs != null ? nowMs : Date.now()
const d = new Date(mtimeMs)
const months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
]
const mon = months[d.getMonth()]
const day = String(d.getDate()).padStart(2, ' ')
const sixMo = 180 * 24 * 3600 * 1000
if (Math.abs(now - mtimeMs) > sixMo) {
const yr = String(d.getFullYear()).padStart(4, ' ')
return mon + ' ' + day + ' ' + yr
}
const hh = String(d.getHours()).padStart(2, '0')
const mm = String(d.getMinutes()).padStart(2, '0')
return mon + ' ' + day + ' ' + hh + ':' + mm
}
/** @param {number} size */
function barePosixBlocks(size) {
return Math.ceil(Number(size) / 512) || 0
}
/**
* Raw stdout for NUL/binary when **`process.stdout.write`** is missing.
* If **`ctx.bareOsBinWrite(Uint8Array|string)`** is set (tests / host), use it.
* @param {Record<string, unknown>} ctx
* @param {string | Uint8Array} chunk
* @returns {boolean}
*/
function bareOsEmitRaw(ctx, chunk) {
if (typeof ctx.bareOsBinWrite === 'function') {
const b4 = ctx.b4a
const u8 =
typeof chunk === 'string'
? b4 && typeof b4.from === 'function'
? b4.from(chunk)
: new TextEncoder().encode(chunk)
: chunk
ctx.bareOsBinWrite(u8 instanceof Uint8Array ? u8 : new Uint8Array(u8))
return true
}
const w = globalThis.process?.stdout?.write
if (typeof w === 'function') {
w.call(globalThis.process.stdout, chunk)
return true
}
return false
}
/** Session env map (`vfs.env`, then `ctx.env`). Never throws. */
function bareOsEnv(ctx) {
const v = ctx && ctx.vfs && ctx.vfs.env
if (v && typeof v === 'object') return v
const e = ctx && ctx.env
if (e && typeof e === 'object') return e
return {}
}
/**
* Strict POSIX-ish decimal integer (no octal, no exponent, no empty).
* @param {unknown} s
* @returns {number}
*/
function bareOsParseDecInt(s) {
const t = String(s == null ? '' : s).trim()
if (!/^[+-]?(?:0|[1-9][0-9]*)$/.test(t)) return NaN
const n = Number.parseInt(t, 10)
return Number.isSafeInteger(n) ? n : NaN
}
/** @param {unknown} s */
function bareOsParseNonNegInt(s) {
const n = bareOsParseDecInt(s)
return n >= 0 ? n : NaN
}
/**
* @param {Record<string, unknown>} ctx
* @param {string} name
* @param {number} fallback
* @param {number} [min]
* @param {number} [max]
*/
function bareOsEnvInt(ctx, name, fallback, min, max) {
const raw = bareOsEnv(ctx)[name]
if (raw == null || raw === '') return fallback
const n = Number.parseInt(String(raw), 10)
if (!Number.isFinite(n)) return fallback
let v = n
if (min != null && v < min) v = min
if (max != null && v > max) v = max
return v
}
/**
* @param {Record<string, unknown>} ctx
* @param {string} msg
* @param {number} [code]
*/
function bareOsFail(ctx, msg, code) {
if (msg) ctx.console.error(msg)
ctx.exitCode = code == null ? 1 : code
}
/** @param {unknown} e */
function bareOsIsNotFoundErr(e) {
const code = e && typeof e === 'object' ? e.code : ''
if (code === 'ENOENT') return true
const msg = String((e && e.message) || e || '')
return /ENOENT|No such file|not found/i.test(msg)
}
/**
* @param {Record<string, unknown>} ctx
* @param {unknown} buf
* @returns {Uint8Array}
*/
function bareOsToU8(ctx, buf) {
if (!buf) return new Uint8Array(0)
if (buf instanceof Uint8Array) return buf
if (ctx && ctx.b4a && typeof ctx.b4a.from === 'function') return ctx.b4a.from(buf)
return new Uint8Array(buf)
}
/** @param {string} dir @param {string} name */
function bareOsJoinPath(dir, name) {
const d = String(dir || '').replace(/\/+$/, '')
const n = String(name || '').replace(/^\/+/, '')
if (!d || d === '/') return '/' + n
return d + '/' + n
}
/** @param {string} p */
function bareOsBaseName(p) {
const t = String(p || '').replace(/\/+$/, '')
if (!t || t === '/') return t === '/' ? '/' : ''
const i = t.lastIndexOf('/')
return i < 0 ? t : t.slice(i + 1) || t
}
/** @param {string} p */
function bareOsParentDir(p) {
const t = String(p || '').replace(/\/+$/, '') || '/'
if (t === '/') return '/'
const i = t.lastIndexOf('/')
return i <= 0 ? '/' : t.slice(0, i) || '/'
}
/** @param {string} p */
function bareOsNormPath(p) {
return String(p || '').replace(/\/+$/, '') || '/'
}
/**
* @param {Record<string, unknown>} ctx
* @param {string} p
*/
function bareOsResolvePath(ctx, p) {
if (ctx && ctx.vfs && typeof ctx.vfs.resolveLogical === 'function') {
try {
return String(ctx.vfs.resolveLogical(p) || p)
} catch {
/* fall through */
}
}
return String(p || '')
}
/**
* True when dest is src or lives under src (self-copy / self-move).
* @param {Record<string, unknown>} ctx
* @param {string} src
* @param {string} dest
*/
function bareOsDestInsideSrc(ctx, src, dest) {
const s = bareOsNormPath(bareOsResolvePath(ctx, src))
const d = bareOsNormPath(bareOsResolvePath(ctx, dest))
if (s === d) return true
if (s === '/') return d !== '/'
return d === s || d.startsWith(s + '/')
}
const BARE_OS_B64_ALPH =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
/** @param {Uint8Array} u8 */
function bareOsB64Encode(u8) {
let out = ''
let i = 0
for (; i + 2 < u8.length; i += 3) {
const n = (u8[i] << 16) | (u8[i + 1] << 8) | u8[i + 2]
out +=
BARE_OS_B64_ALPH[(n >> 18) & 63] +
BARE_OS_B64_ALPH[(n >> 12) & 63] +
BARE_OS_B64_ALPH[(n >> 6) & 63] +
BARE_OS_B64_ALPH[n & 63]
}
const rest = u8.length - i
if (rest === 1) {
const n = u8[i] << 16
out += BARE_OS_B64_ALPH[(n >> 18) & 63] + BARE_OS_B64_ALPH[(n >> 12) & 63] + '=='
} else if (rest === 2) {
const n = (u8[i] << 16) | (u8[i + 1] << 8)
out +=
BARE_OS_B64_ALPH[(n >> 18) & 63] +
BARE_OS_B64_ALPH[(n >> 12) & 63] +
BARE_OS_B64_ALPH[(n >> 6) & 63] +
'='
}
return out
}
/**
* RFC 4648 Base64 decode (also accepts URL-safe alphabet). Rejects junk.
* @param {string} s
* @returns {Uint8Array}
*/
function bareOsB64Decode(s) {
const t = String(s).replace(/\s+/g, '')
if (!t) return new Uint8Array(0)
if (t.length % 4 === 1) throw new Error('invalid base64 length')
let pad = 0
if (t.endsWith('==')) pad = 2
else if (t.endsWith('=')) pad = 1
const body = pad ? t.slice(0, t.length - pad) : t
const bytes = []
let buf = 0
let bits = 0
for (let i = 0; i < body.length; i++) {
const c = body[i]
let v = BARE_OS_B64_ALPH.indexOf(c)
if (v < 0) {
if (c === '-') v = 62
else if (c === '_') v = 63
else throw new Error('invalid base64 character')
}
buf = (buf << 6) | v
bits += 6
if (bits >= 8) {
bits -= 8
bytes.push((buf >> bits) & 255)
}
}
if (pad) {
const want = Math.floor((body.length * 6) / 8)
if (bytes.length > want) bytes.length = want
}
return new Uint8Array(bytes)
}
/**
* @param {string} s
* @returns {Uint8Array}
*/
function bareOsHexDecode(s) {
const t = String(s).replace(/\s+/g, '')
if (t.length % 2 !== 0) throw new Error('odd hex length')
const out = new Uint8Array(t.length / 2)
for (let i = 0; i < out.length; i++) {
const pair = t.slice(i * 2, i * 2 + 2)
if (!/^[0-9a-fA-F]{2}$/.test(pair)) throw new Error('invalid hex')
out[i] = Number.parseInt(pair, 16)
}
return out
}
/** @param {Uint8Array} u8 */
function bareOsHexEncode(u8) {
let s = ''
for (let i = 0; i < u8.length; i++) s += u8[i].toString(16).padStart(2, '0')
return s
}
/**
* curDepth is distance from the search root directory (0 at the initial path).
* Printed paths use gnu-like depth curDepth + 1 (immediate children of the root are depth 1).
*/
function findEmitLine(ctx, path, print0) {
if (!print0) {
ctx.console.log(path)
return
}
if (!bareOsEmitRaw(ctx, path + '\0')) {
ctx.console.error(
'find: -print0 requires process.stdout.write or ctx.bareOsBinWrite'
)
ctx.exitCode = 1
}
}
/** @param {string} s */
function parseMtimeSpec(s) {
const t = String(s)
let op = ''
let num = t
if (t.startsWith('+')) {
op = '+'
num = t.slice(1)
} else if (t.startsWith('-') && t.length > 1) {
op = '-'
num = t.slice(1)
}
const n = Number.parseFloat(num)
if (!Number.isFinite(n)) return null
return { op, n }
}
/** @param {{ op: string, n: number }} spec */
function findMatchMtime(st, spec) {
const days = (Date.now() - st.mtimeMs) / 86400000
if (spec.op === '+') return days > spec.n
if (spec.op === '-') return days < spec.n
return days >= spec.n && days < spec.n + 1
}
/**
* Device id sketch for `find -xdev` (do not cross `/mnt/<label>` boundaries vs system/personal).
* @param {Record<string, unknown>} ctx
* @param {string} absLogical
*/
function findRouteDevId(ctx, absLogical) {
const a = String(absLogical).replace(/\/+$/, '') || '/'
if (a.startsWith('/mnt/')) {
const label = a.slice(5).split('/').filter(Boolean)[0]
return label ? `mnt:${label}` : 'mnt:'
}
if (a === '/mnt') return 'mnt-root'
const vfs = ctx.vfs
if (!vfs || typeof vfs.route !== 'function') return 'unknown'
const r = vfs.route(absLogical)
if (r.virtualPseudo) return 'pseudo'
if (r.virtualHomeDir) return 'personal-home'
if (r.virtualVarRoot) return 'personal-var'
if (a.startsWith('/tmp')) return 'personal'
if (a.startsWith('/home/')) return 'personal'
if (a.startsWith('/var/')) return 'personal'
return 'system'
}
/** @param {string} s */
function parsePermSpec(s) {
const t = String(s).trim()
if (t.startsWith('/')) return null
let body = t
let allBitsSet = false
if (t.startsWith('-')) {
allBitsSet = true
body = t.slice(1)
}
if (!/^[0-7]{1,4}$/.test(body)) return null
const mask = Number.parseInt(body, 8) & 0o7777
return { allBitsSet, mask }
}
/** @param {Record<string, unknown>} st @param {{ allBitsSet: boolean, mask: number }} spec */
function findMatchPerm(st, spec) {
const mode =
typeof st.mode === 'number'
? st.mode & 0o7777
: typeof st.mode === 'string'
? Number.parseInt(String(st.mode), 8) & 0o7777
: 0
if (spec.allBitsSet) return (mode & spec.mask) === spec.mask
return mode === spec.mask
}
async function findIsEmpty(ctx, path, st) {
if (st.type === 'file' || st.type === 'symlink') return (st.size || 0) === 0
if (st.type !== 'directory') return false
const names = await ctx.vfs.readdir(path)
const rest = names.filter((n) => n !== '.bareos_empty')
return rest.length === 0
}
/**
* @param {Record<string, unknown>} ctx
* @param {string} dir
* @param {Record<string, unknown>} o
* @param {number} curDepth
*/
async function walk(ctx, dir, o, curDepth) {
if (o.maxDepth >= 0 && curDepth > o.maxDepth) return
let names
try {
names = await ctx.vfs.readdir(dir)
} catch (e) {
ctx.console.error('find: ' + dir + ': ' + ((e && e.message) || e))
ctx.exitCode = 1
return
}
for (const n of names) {
if (n === '.bareos_empty') continue
const path = dir.replace(/\/+$/, '') + '/' + n
let st
try {
st = await ctx.vfs.lstat(path)
} catch {
continue
}
if (!st) continue
const gnuDepth = curDepth + 1
const pathOk = !o.pathRe || o.pathRe.test(path)
const nameOk = !o.nameRe || o.nameRe.test(n)
let match = pathOk && nameOk && (!o.wantType || st.type === o.wantType)
if (match && o.mtimeSpec) match = match && findMatchMtime(st, o.mtimeSpec)
if (match && o.permSpec) match = match && findMatchPerm(st, o.permSpec)
if (match && o.newerThanMs != null)
match = match && st.mtimeMs > o.newerThanMs
if (match && o.wantEmpty) {
match = match && (await findIsEmpty(ctx, path, st))
}
if (match && o.regexPath && !o.regexPath.test(path)) match = false
const consider = async () => {
if (!(match && gnuDepth >= o.minDepth)) return
if (o.doDelete) {
if (ctx.vfs.env.BARE_OS_FIND_DELETE !== '1') {
const stw = /** @type {{ warned?: boolean }} */ (o.deleteState)
if (!stw.warned) {
ctx.console.error(
'find: -delete disabled (set BARE_OS_FIND_DELETE=1 to confirm)'
)
stw.warned = true
}
ctx.exitCode = 1
} else {
try {
await ctx.vfs.rm(path, { recursive: true, force: true })
} catch (e) {
ctx.console.error('find: ' + path + ': ' + (e.message || e))
ctx.exitCode = 1
}
}
} else if (o.execTemplate && o.execTemplate.length) {
if (typeof ctx.runBinCommand !== 'function') {
const stw = /** @type {{ noRun?: boolean }} */ (o.deleteState)
if (!stw.noRun) {
ctx.console.error('find: -exec requires ctx.runBinCommand')
stw.noRun = true
}
ctx.exitCode = 1
} else if (o.execCount >= o.execMax) {
const stw = /** @type {{ execCap?: boolean }} */ (o.deleteState)
if (!stw.execCap) {
ctx.console.error(
'find: -exec/-ok: invocation limit (' +
o.execMax +
') exceeded (raise BARE_OS_FIND_EXEC_MAX)'
)
stw.execCap = true
}
ctx.exitCode = 1
} else {
const ok =
!o.execUseOk ||
ctx.vfs.env.BARE_OS_FIND_OK === '1' ||
ctx.vfs.env.BARE_OS_FIND_OK === 'true'
if (o.execUseOk && !ok) {
/* skip without running */
} else {
const subst = o.execTemplate.map((arg) =>
arg === '{}' ? path : arg.split('{}').join(path)
)
o.execCount++
await ctx.runBinCommand(subst)
}
}
} else {
findEmitLine(ctx, path, o.print0)
}
}
const shouldRecurse = st.type === 'directory'
let skipRecurse = false
if (shouldRecurse) {
if (o.xdevRootDev != null) {
const subDev = findRouteDevId(ctx, path)
if (subDev !== o.xdevRootDev) skipRecurse = true
}
const absPath = ctx.vfs.resolveLogical(path)
if (o.pruneAbs && absPath === o.pruneAbs) skipRecurse = true
}
if (!o.depthFirst) await consider()
if (shouldRecurse && !skipRecurse) await walk(ctx, path, o, curDepth + 1)
if (o.depthFirst) await consider()
}
}
async function run(ctx, argv) {
let maxDepth = -1
let minDepth = 0
let depthFirst = false
/** @type {string | null} */
let nameGlob = null
/** @type {string | null} */
let pathGlob = null
/** @type {'file' | 'directory' | 'symlink' | null} */
let wantType = null
let nameIgnoreCase = false
let print0 = false
/** @type {{ op: string, n: number } | null} */
let mtimeSpec = null
/** @type {{ allBitsSet: boolean, mask: number } | null} */
let permSpec = null
let xdev = false
/** @type {string | null} */
let newerPath = null
/** @type {string | null} */
let prunePath = null
let wantEmpty = false
let doDelete = false
/** @type {string[] | null} */
let execTemplate = null
let execUseOk = false
/** @type {string | null} */
let regexPathStr = null
const rest = []
for (let i = 1; i < argv.length; i++) {
const a = argv[i]
if (a === '-depth') {
depthFirst = true
continue
}
if (a === '-maxdepth' && argv[i + 1]) {
maxDepth = bareOsParseNonNegInt(argv[++i])
if (!Number.isFinite(maxDepth)) {
ctx.console.error('find: invalid -maxdepth')
ctx.exitCode = 1
return
}
continue
}
if (a === '-mindepth' && argv[i + 1]) {
minDepth = bareOsParseNonNegInt(argv[++i])
if (!Number.isFinite(minDepth)) {
ctx.console.error('find: invalid -mindepth')
ctx.exitCode = 1
return
}
continue
}
if (a === '-path' && argv[i + 1]) {
pathGlob = argv[++i]
continue
}
if (a === '-name' && argv[i + 1]) {
nameGlob = argv[++i]
nameIgnoreCase = false
continue
}
if (a === '-iname' && argv[i + 1]) {
nameGlob = argv[++i]
nameIgnoreCase = true
continue
}
if (a === '-type' && argv[i + 1]) {
const t = argv[++i]
if (t === 'f') wantType = 'file'
else if (t === 'd') wantType = 'directory'
else if (t === 'l') wantType = 'symlink'
continue
}
if (a === '-print0') {
print0 = true
continue
}
if (a === '-mtime' && argv[i + 1]) {
mtimeSpec = parseMtimeSpec(argv[++i])
if (!mtimeSpec) {
ctx.console.error('find: invalid -mtime')
ctx.exitCode = 1
return
}
continue
}
if (a === '-perm' && argv[i + 1]) {
permSpec = parsePermSpec(argv[++i])
if (!permSpec) {
ctx.console.error('find: invalid -perm')
ctx.exitCode = 1
return
}
continue
}
if (a === '-xdev') {
xdev = true
continue
}
if (a === '-newer' && argv[i + 1]) {
newerPath = argv[++i]
continue
}
if (a === '-prune' && argv[i + 1]) {
prunePath = argv[++i]
continue
}
if (a === '-empty') {
wantEmpty = true
continue
}
if (a === '-delete') {
doDelete = true
continue
}
if ((a === '-exec' || a === '-ok') && argv[i + 1]) {
execUseOk = a === '-ok'
i++
const parts = []
while (i < argv.length && argv[i] !== ';') {
parts.push(argv[i++])
}
if (i >= argv.length || argv[i] !== ';') {
ctx.console.error('find: ' + a + ' must be terminated with ;')
ctx.exitCode = 1
return
}
i++
if (!parts.length) {
ctx.console.error('find: empty ' + a)
ctx.exitCode = 1
return
}
execTemplate = parts
continue
}
if (a === '-regex' && argv[i + 1]) {
const pat = argv[++i]
try {
new RegExp(pat)
regexPathStr = pat
} catch {
ctx.console.error('find: invalid -regex')
ctx.exitCode = 1
return
}
continue
}
if (a === '--') {
rest.push(...argv.slice(i + 1))
break
}
if (a.startsWith('-')) {
ctx.console.error('find: unsupported ' + a)
ctx.exitCode = 1
return
}
rest.push(a)
}
const root = rest[0] || '.'
let nameRe = null
if (nameGlob) {
const esc = nameGlob
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
.replace(/\*/g, '.*')
.replace(/\?/g, '.')
nameRe = new RegExp('^' + esc + '$', nameIgnoreCase ? 'i' : '')
}
let pathRe = null
if (pathGlob) {
const esc = pathGlob
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
.replace(/\*\*/g, '\0GLOBSTAR\0')
.replace(/\*/g, '[^/]*')
.replace(/\?/g, '[^/]')
.replace(/\0GLOBSTAR\0/g, '.*')
pathRe = new RegExp('^' + esc + '$')
}
/** @type {number | null} */
let newerThanMs = null
if (newerPath) {
try {
const st = await ctx.vfs.stat(newerPath)
if (!st) {
ctx.console.error('find: ' + newerPath + ': No such file')
ctx.exitCode = 1
return
}
newerThanMs = st.mtimeMs
} catch (e) {
ctx.console.error('find: ' + newerPath + ': ' + (e.message || e))
ctx.exitCode = 1
return
}
}
/** @type {string | null} */
let pruneAbs = null
if (prunePath) {
pruneAbs = ctx.vfs.resolveLogical(prunePath).replace(/\/+$/, '') || '/'
}
/** @type {RegExp | null} */
let regexPath = null
if (regexPathStr) {
try {
regexPath = new RegExp(regexPathStr)
} catch {
ctx.console.error('find: invalid -regex')
ctx.exitCode = 1
return
}
}
const execMaxRaw = ctx.vfs.env.BARE_OS_FIND_EXEC_MAX
let execMax = 64
if (execMaxRaw != null && String(execMaxRaw).trim() !== '') {
const n = Number.parseInt(String(execMaxRaw), 10)
if (Number.isFinite(n)) execMax = Math.min(4096, Math.max(1, n))
}
const abs = ctx.vfs.resolveLogical(root)
try {
const stRoot = await ctx.vfs.lstat(abs)
if (!stRoot) {
ctx.console.error('find: ' + root + ': No such file or directory')
ctx.exitCode = 1
return
}
} catch (e) {
ctx.console.error('find: ' + root + ': ' + ((e && e.message) || String(e)))
ctx.exitCode = 1
return
}
const xdevRootDev = xdev ? findRouteDevId(ctx, abs) : null
const o = {
maxDepth,
minDepth,
nameRe,
pathRe,
wantType,
print0,
mtimeSpec,
permSpec,
xdevRootDev,
newerThanMs,
pruneAbs,
wantEmpty,
doDelete,
regexPath,
execTemplate,
execUseOk,
execCount: 0,
execMax,
deleteState: {},
depthFirst
}
if (minDepth <= 0) {
try {
const stRoot = await ctx.vfs.lstat(abs)
if (stRoot) {
const pathOk = !o.pathRe || o.pathRe.test(abs)
const nameOk =
!o.nameRe || o.nameRe.test(bareOsBaseName(abs) === '/' ? '.' : bareOsBaseName(abs))
let match = pathOk && nameOk && (!o.wantType || stRoot.type === o.wantType)
if (match && o.mtimeSpec) match = match && findMatchMtime(stRoot, o.mtimeSpec)
if (match && o.permSpec) match = match && findMatchPerm(stRoot, o.permSpec)
if (match && o.newerThanMs != null)
match = match && stRoot.mtimeMs > o.newerThanMs
if (match && o.wantEmpty) match = match && (await findIsEmpty(ctx, abs, stRoot))
if (match && o.regexPath && !o.regexPath.test(abs)) match = false
if (match && !o.doDelete && !o.execTemplate) {
if (!depthFirst) findEmitLine(ctx, abs, o.print0)
}
}
} catch {
/* walk will report */
}
}
await walk(ctx, abs, o, 0)
if (minDepth <= 0 && depthFirst) {
try {
const stRoot = await ctx.vfs.lstat(abs)
if (stRoot && !o.doDelete && !o.execTemplate) {
const pathOk = !o.pathRe || o.pathRe.test(abs)
const nameOk =
!o.nameRe || o.nameRe.test(bareOsBaseName(abs) === '/' ? '.' : bareOsBaseName(abs))
if (pathOk && nameOk && (!o.wantType || stRoot.type === o.wantType)) {
findEmitLine(ctx, abs, o.print0)
}
}
} catch {
/* already reported */
}
}
}