/** * POSIX `link` utility — delegates to `ctx.bareOsSyscall('link', …)` (copy-on-Hyperdrive semantics). */ async function run(ctx, argv) { const args = [] let endOpts = false for (let i = 1; i < argv.length; i++) { const a = argv[i] if (!endOpts && a === '--') { endOpts = true continue } if (!endOpts && (a === '-h' || a === '--help') && args.length === 0) { 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 (!endOpts && a.startsWith('-')) { ctx.console.error('link: unsupported option or operand order') ctx.exitCode = 1 return } args.push(a) } if (args.length !== 2) { ctx.console.error('usage: link FILE1 FILE2') 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 } }