#!/usr/bin/env node // A FAKE `udisksctl`, driven by the same control file as fake-findmnt. // // Two call shapes, both from `common/lib/storageVolumes.ts`: // // 1. udisksctl --version → the availability probe (memoised) // 2. udisksctl mount -b /dev/disk/by-uuid/ // → "Mounted /dev/fake1 at ." on success; a non-zero exit with // the daemon's words on stderr otherwise (a polkit denial is the // expected real-world failure, and the probe surfaces it verbatim) // // `mountable` in `/.fake-findmnt.json` maps uuid → the // mountpoint a mount would produce, and mounting ADDS the volume to `mounts` // so a following findmnt sees it. With no control file nothing is mountable, // which is what `resetData()` leaves behind. import { readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; const argv = process.argv.slice(2); if (argv.includes("--version")) { process.stdout.write("udisksctl 2.10.1 (fake)\n"); process.exit(0); } const controlPath = process.env.TRANSCRIPTS_DIR ? path.join(process.env.TRANSCRIPTS_DIR, ".fake-findmnt.json") : null; function read() { if (!controlPath) return null; try { return JSON.parse(readFileSync(controlPath, "utf8")); } catch { return null; } } if (argv[0] === "mount") { const i = argv.indexOf("-b"); const dev = i >= 0 && i + 1 < argv.length ? argv[i + 1] : ""; const uuid = path.basename(dev); const control = read(); const target = control?.mountable?.[uuid]; if (!target) { process.stderr.write( `Error mounting ${dev}: GDBus.Error:org.freedesktop.UDisks2.Error.Failed: ` + `No such device (fake)\n`, ); process.exit(1); } const mounts = Array.isArray(control.mounts) ? control.mounts : []; if (!mounts.some((m) => m.uuid === uuid)) { mounts.push({ uuid, target, source: "/dev/fake1", fstype: "ext4" }); writeFileSync( controlPath, JSON.stringify({ ...control, mounts }, null, 2) + "\n", ); } process.stdout.write(`Mounted /dev/fake1 at ${target}.\n`); process.exit(0); } process.exit(0);