Skip to content

ln: create links through the open target directory - #15524

Open
abendrothj wants to merge 2 commits into
uutils:mainfrom
abendrothj:ln-target-dir-anchor
Open

abendrothj wants to merge 2 commits into
uutils:mainfrom
abendrothj:ln-target-dir-anchor

Conversation

@abendrothj

@abendrothj abendrothj commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Based on #15122; only the last commit is new here (+278/−49).

Closes #15523

With a target directory, ln checked it once and then created each link and renamed each backup by joining the directory's path, so a rename of that path in between sent the remaining links elsewhere.

ln now opens the target directory once and does everything relative to it: the existence check, choosing a backup name, the backup rename, and creating or replacing the link. ., .. and / as sources resolve as before. The -r link text and the same-file checks still use the path. uucore gets backup_control::get_backup_path_with_exists, so numbered backup names are checked in the same directory, and fs::link_at becomes public.

On macOS, a target directory without search permission now fails once with "failed to access" instead of once per source. Linux opens it with O_PATH, so nothing changes there.

Checked against GNU 9.12 with the target renamed while ln waits at an -i prompt, with and without --backup: links and backups stay in the original directory, as in GNU. Added test_target_dir_renamed_during_prompt, which fails without the change on macOS and Linux, and test_target_dir_backup_source_without_basename for sources without a basename.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 12:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/follow-symlink is no longer failing!

@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 6.11%

1 warning, 1 note

⚠️ 123 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
✅ 400 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation hostname_ip_lookup[100000] 175.8 µs 165.6 µs +6.11%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing abendrothj:ln-target-dir-anchor (c30e23a) with main (ff0c589)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (732b9c5) during the generation of this report, so ff0c589 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread src/uu/ln/src/ln.rs Outdated
Comment thread src/uu/ln/src/ln.rs Outdated
Comment thread src/uu/ln/src/ln.rs Outdated
Copilot AI balanced review requested due to automatic review settings October 20, 2026 00:48
@abendrothj
abendrothj force-pushed the ln-target-dir-anchor branch from 71a3e69 to f6794f9 Compare October 20, 2026 00:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@xtqqczze

This comment was marked as resolved.

@abendrothj
abendrothj force-pushed the ln-target-dir-anchor branch from f6794f9 to eb937fb Compare October 22, 2026 06:44
Copilot AI balanced review requested due to automatic review settings October 22, 2026 06:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@xtqqczze

Copy link
Copy Markdown
Collaborator

Comment thread src/uu/ln/src/ln.rs
Copilot AI balanced review requested due to automatic review settings October 23, 2026 08:09
@abendrothj
abendrothj force-pushed the ln-target-dir-anchor branch from eb937fb to f36e668 Compare October 23, 2026 08:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.07 MB (-272 KB, -0.17%)

Significant per-binary changes:
  date     2.61 MB ->    2.30 MB  (-316 KB, -11.81%)

Move the temporary name and renameat logic of replace_link into
DirFd::replace_entry_at, which creates the entry through a callback
relative to the directory, so other callers can replace entries the
same way.

The parent is now opened with DirFd::open_anchor, so ln -sf and cp -sf
replacing an entry in a directory with write and search but no read
permission work, as they do with GNU, instead of failing with EACCES.
@sylvestre
sylvestre force-pushed the ln-target-dir-anchor branch from f36e668 to c30e23a Compare October 25, 2026 09:31
Copilot AI balanced review requested due to automatic review settings October 25, 2026 09:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

This branch has not been deployed

No deployments
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.

ln -t: a renamed target directory redirects the remaining links

4 participants