diff options
| author | Soccera1 <[email protected]> | 2026-07-18 09:27:17 +1000 |
|---|---|---|
| committer | Soccera1 <[email protected]> | 2026-07-18 09:27:17 +1000 |
| commit | 6f5241afb5bd1d6a1a8724bf06cc6f205c279402 (patch) | |
| tree | 2aa852e968f6b89f2c8458333ce3e7c38b3c2450 /src/commands/mkfifo.js | |
| parent | a753f669c9bedfccb9f7f400da018bb487dca5d0 (diff) | |
| download | bnu-6f5241afb5bd1d6a1a8724bf06cc6f205c279402.tar.gz bnu-6f5241afb5bd1d6a1a8724bf06cc6f205c279402.zip | |
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); |
