/** * Persist an operator-facing snapshot of HDMS mounts on the system drive. * Source of truth remains `/.bare/hdms/registry.json` on the personal drive. */ import b4a from 'b4a' /** * @param {{ writeFile?: Function, mkdir?: Function } | null | undefined} vfs * @param {import('./hdms-manager.js').HdmsController | null | undefined} hdms */ export async function persistBareOsMountsSnapshot(vfs, hdms) { if (!vfs || typeof vfs.writeFile !== 'function') return if (!hdms?.active || !hdms.registry) return /** @type {{ label: string, target: string, mode: string, readOnly: boolean, key?: string, ns?: string }[]} */ const mounts = [] for (const d of hdms.registry.drives) { mounts.push({ label: d.label, target: `/mnt/${d.label}`, mode: d.mode, readOnly: d.mode === 'readonly', ...(d.key ? { key: d.key } : {}), ...(d.ns ? { ns: d.ns } : {}) }) } const doc = { schemaVersion: 1, updatedAt: new Date().toISOString(), note: 'Snapshot for operators; authoritative registry is /.bare/hdms/registry.json on the personal drive. When writable, the same JSON is mirrored at /.bare/os/mounts_last.json for multi-drive tooling.', mounts } const body = JSON.stringify(doc, null, 2) + '\n' const buf = b4a.from(body, 'utf8') try { await vfs.mkdir('/etc/bare-os', { recursive: true }) } catch { /* exists or pseudo */ } try { await vfs.writeFile('/etc/bare-os/mounts.json', buf) } catch (e) { console.warn('[bare-os] mounts.json persist failed:', e?.message || e) } try { await vfs.mkdir('/.bare/os', { recursive: true }) await vfs.writeFile('/.bare/os/mounts_last.json', buf) } catch { /* personal tree may be unavailable in minimal tests */ } }