From c11e17573334dfb487a8e1cc25fa84fa9e138f5c Mon Sep 17 00:00:00 2001 From: Lily <129828376+Soccera1@users.noreply.github.com> Date: Tue, 28 Jul 2026 16:12:21 +1000 Subject: Refactor coreutils into single-call command modules (#1) * Refactor to single call --- src/commands/mkfifo.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/commands/mkfifo.js (limited to 'src/commands/mkfifo.js') 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); -- cgit v1.3