// Host-only adapters for the root coordinator. Workers cannot select these paths. import { lstatSync } from 'node:fs'; import { dirname } from 'node:path'; import { bindingDataDir } from './binding.mjs'; import { requestProcessingStop, clearProcessingStop } from './journal.mjs'; import { listRuntimes, unregisterRuntime } from '../../processing-control/src/runtimes.mjs'; function journal(root, record) { const dir = bindingDataDir(root, record.run); for (const path of [dirname(dir), dir]) { const st = lstatSync(path); if (!st.isDirectory() || st.isSymbolicLink() || st.uid !== process.getuid() || (st.mode & 0o077)) throw new Error('processing-discord-path-unsafe'); } return dir; } export function discordProcessingHooks(dataRoot) { return { beforeStop(record, generation) { if (record.kind === 'discord') requestProcessingStop(journal(dataRoot, record), generation); }, onResume(generation) { for (const r of listRuntimes(dataRoot)) { if (r.kind === 'discord' && r.haltGeneration === generation) { clearProcessingStop(journal(dataRoot, r), generation); unregisterRuntime(dataRoot, r.id); } } }, }; }