/** * POSIX `link` utility — delegates to `ctx.bareOsSyscall('link', …)` (copy-on-Hyperdrive semantics). */ async function run(ctx, argv) { const args = argv.slice(1).filter((a) => a !== '--') if (args.length === 1 && (args[0] === '-h' || args[0] === '--help')) { ctx.console.log( 'usage: link FILE1 FILE2\nCreate FILE2 linked to FILE1 (hard link semantics; on Hyperdrive this copies bytes unless the host enforces EOPNOTSUPP).' ) return } if (args.length !== 2) { ctx.console.error('usage: link FILE1 FILE2') ctx.exitCode = 1 return } if (args[0].startsWith('-') || args[1].startsWith('-')) { ctx.console.error('link: unsupported option or operand order') ctx.exitCode = 1 return } let existing = args[0] let newPath = args[1] if (ctx.vfs && typeof ctx.vfs.resolveLogical === 'function') { existing = ctx.vfs.resolveLogical(existing) newPath = ctx.vfs.resolveLogical(newPath) } if (typeof ctx.bareOsSyscall !== 'function') { ctx.console.error('link: bareOsSyscall unavailable') ctx.exitCode = 1 return } try { await ctx.bareOsSyscall('link', { existing, newPath }) } catch (e) { ctx.console.error('link: ' + ((e && e.message) || e)) ctx.exitCode = 1 } }