diff options
| author | Lily <[email protected]> | 2026-07-28 16:12:21 +1000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-28 16:12:21 +1000 |
| commit | c11e17573334dfb487a8e1cc25fa84fa9e138f5c (patch) | |
| tree | e91dbd19b524f9432da6bcb86b1fc193e0d02e26 /src/commands/mkfifo.js | |
| parent | 6a2f098e72e71437154ec00506e8e736aa8e1026 (diff) | |
| download | bnu-c11e17573334dfb487a8e1cc25fa84fa9e138f5c.tar.gz bnu-c11e17573334dfb487a8e1cc25fa84fa9e138f5c.zip | |
Refactor coreutils into single-call command modules (#1)
* Refactor to single call
Diffstat (limited to 'src/commands/mkfifo.js')
| -rw-r--r-- | src/commands/mkfifo.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/commands/mkfifo.js b/src/commands/mkfifo.js new file mode 100644 index 0000000..0491c2f --- /dev/null +++ b/src/commands/mkfifo.js @@ -0,0 +1,29 @@ +#!/usr/bin/env bun + +import { cstr, libc, parseOptions } from "../shared/common.js"; +import { UsageError } from "../shared/diagnostics.js"; +import { ensureSpecialFileCreatable, normalizeSpecialFileLongOptions, parseSpecialFileCreationMode, selinuxCreationOptions, setFileMode, specialFileMetaOption, specialFileQuotedName, withSelinuxCreationContext } from "../shared/filesystem.js"; +import { defineCommand, runAsMain } from "../shared/command.js"; + +export async function mkfifoCmd(args) { + args = normalizeSpecialFileLongOptions(args); + const { opts, operands } = parseOptions(args, { short: { m: "value", Z: false }, long: { mode: "value", context: "optional-value", help: false, version: false } }); + const securityContext = selinuxCreationOptions("mkfifo", opts); + if (!operands.length) throw new UsageError("missing operand", true); + const explicitMode = opts.m ?? opts.mode; + const mode = explicitMode ? parseSpecialFileCreationMode(explicitMode) : 0o666; + await withSelinuxCreationContext("mkfifo", securityContext, async (created) => { + for (const path of operands) { + await ensureSpecialFileCreatable("mkfifo", path, "fifo"); + if (libc.symbols.mkfifo(cstr(path), mode) !== 0) throw new UsageError(`cannot create fifo ${specialFileQuotedName(path)}: Operation not permitted`); + if (explicitMode) await setFileMode(path, mode); + await created(path); + } + }); + return 0; +} + +const singleCall = defineCommand("mkfifo", mkfifoCmd, (args) => specialFileMetaOption("mkfifo", args)); +export default singleCall; + +if (import.meta.main) await runAsMain(singleCall); |
