Skip to content

fix(cli): reject hard-linked input files as outputs - #1797

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
sebastian-griego:fix/cli-output-input-links
Oct 21, 2026
Merged

Lorenzobattistela merged 2 commits into
bendlang:mainfrom
sebastian-griego:fix/cli-output-input-links

Conversation

@sebastian-griego

Copy link
Copy Markdown
Contributor

bend main.bend -o out.js can overwrite main.bend when out.js is a hard link to it. The current output check resolves paths, but hard links have distinct paths. The command succeeds and replaces the source with compiled JavaScript.

Use the existing same_file helper to compare each existing output with the program's inputs by device and inode. Reject a match before writing the output. Keep the current path and directory checks.

The regression test covers the entry file, imported Bend files, and foreign JS and C files. It checks direct paths, symbolic links, hard links, output formats, directories, and valid output creation and replacement. Each rejected output must leave all inputs unchanged.

Validation:

  • The new regression test prints 3 before the fix and the expected 0 after it.
  • Seven fixtures pass in the CLI and compiled JS. Two also pass as native binaries: 16 local runtime checks.
  • The repository gate passes: PASS: 54 / 54.
  • TypeScript reports the same 11 diagnostics on current main and this change. The full type check does not pass on either version.
  • Cluster gates were not run.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 21, 2026
A rejected output used to fail the build after the earlier outputs were
written. The test builds 9 times instead of 19, in the system temp dir, and
covers a rejected second output.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Lorenzobattistela
Lorenzobattistela merged commit 350b4ec into bendlang:main Oct 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants