Files
bare-operating-system/packages/bare-os-coreutils/src/mktemp.js
T
Raven Scott 64a1270d18 - disk.os: replication_operator_sketch schema 7 + corestoreSnapshotUxHint; wire corestore into bridge
- HRPC: bare_os.pkg_index_get, route table schema 3; pkg-swarm-index list/get; pathcap-verify --trusted
- POSIX: profile 1.0.17, ctx API 1.53.0, syscalls.json schema 11 + susv4Refs; JSON schemas + matrix/dashboard
- Feature bits: BARE_OS_KERNEL_FEATURE_BITS_DOC 16; contract + verify scripts; ctx.d.ts + gen helper sync
- Ops: BARE_OS_HOLEPUNCH_DRIFT_TIER1 + tier1Repos; mktemp avoids false XXX marker; /proc boot_budget_summary test list
- Docs: contract spine, env appendix, handbook, compatibility matrix, boot budget schema, vault threat model notes

Covers bare-os P2P roadmap items 1–20 where implemented in-tree; kernel/lib/bare/README left minimal per maintainer edit.
2026-04-05 15:52:59 -04:00

28 lines
914 B
JavaScript

async function run(ctx, argv) {
let wantDir = false
/** @type {string | null} */
let template = null
for (let i = 1; i < argv.length; i++) {
const a = argv[i]
if (a === '-d') wantDir = true
else if (!a.startsWith('-')) template = a
}
const rnd = () =>
Math.random().toString(36).slice(2, 10) +
Math.random().toString(36).slice(2, 6)
const sixX = 'X'.repeat(6)
let rel = template || `tmp.${sixX}`
if (rel.includes(sixX)) rel = rel.replace(new RegExp(sixX, 'g'), rnd())
else rel = `${rel.replace(/\/+$/, '')}.${rnd()}`
const full = rel.startsWith('/') ? rel : `/tmp/${rel.replace(/^\/+/, '')}`
try {
if (wantDir) await ctx.vfs.mkdir(full, { recursive: false })
else await ctx.vfs.writeFile(full, ctx.b4a.from(''))
ctx.console.log(full)
ctx.exitCode = 0
} catch (e) {
ctx.console.error('mktemp: ' + ((e && e.message) || e))
ctx.exitCode = 1
}
}