[PR #7265] [MERGED] Content root: hard-link the base files on Windows instead of copying them #7452

Closed
opened 2026-11-03 06:39:44 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7265
Author: @mmmaarian03-crypto
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/windows-content-hardlinks


📝 Commits (1)

  • 7bd3ccc Content root: hard-link the base files on Windows instead of copying them

📊 Changes

2 files changed (+183 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/mod_content.rs (+18 -1)
📝 crates/horizon-client/src/mod_content_tests.rs (+165 -0)

📄 Description

🤖 Opened by Marian's AI agent (Claude), not by Marian himself.

What and why

Fixes #7257.

On Windows, mod_content::link copies every file of the prepared resource root into the content root
(.horizon-cache/mod-content) when a content mod is on; on Unix it makes a symlink. That is ~28,000 files and 0.6 GiB
written again on every rebuild, and the root is rebuilt after every update, because its stamp holds the executable's
path, size and date.

This makes the Windows link of a file a hard link (std::fs::hard_link, no privilege needed on NTFS), and falls
back to the copy when no link can be made: another volume, a filesystem without links, the NTFS limit of 1023 links to
a file. A symlink in the base is still copied through, as fs::copy always did. Nothing else changes: the walk, the
errors and the Unix side are the same, and the resulting root is byte-identical. It is what the resource-pack overlay's
link in packs.rs already does; this is the same change for the content root, which still copies.

step of a rebuild, replayed on disk (28,177 base files, 251 rewritten tables, 116,244 mod files; NVMe, Defender on) copy hard link
the base: copied / linked 22.9 · 34.1 · 16.5 s 9.7 · 8.9 · 7.1 s
everything build does to files (base, tables, mod files) 60.8 – 110.5 s 52.7 – 59.1 s

Three runs each, order alternated, measured on the earlier base 8a7cd0dea. The replay writes random bytes with the
sizes of a real 76-mod pack's root, so it measures file operations only, not the JSON work. The real build() on a
prepared root with one small mod (the ignored content_root_is_reused_until_a_mod_changes: one build and one rebuild)
took 37.0 / 40.7 s with copies and 23.9 / 22.2 s with links, same volume.

Why it is safe. A hard link shares the base file's data, so an in-place write into the root would write into the
base. The root is never written in place: Overlay::write removes the name and then writes, out_path is only read,
the stamp is a file of the root's own, and the prepared-data file (horizon_core::prepared_files::write) is written
through a temporary file renamed into place, and link_children already leaves it out. The rest of the game only reads
the root, except the sprite cache, which also writes a temporary file and renames it over the name. I looked for
fs::write, File::create and OpenOptions on resource paths: tests only besides those. horizon-prepare's "never
hard links" note is about the copies the exporters write into the prepared root, which this does not touch.

Not in this PR.

  • The stamp. It is what stops a rebuilt game from serving a root made by older code; reusing it across updates needs
    a content identity of the code that builds the root, a maintainers' decision.
  • Directory junctions, as packs.rs makes for untouched directories: Overlay::dir replaces a symlinked directory
    with remove_file, which Windows refuses for a junction, so it is a bigger change.

Tests: the_overlay_shares_the_base_files (fails on the copy: the base file is edited in place and must show in the
root; runs on Unix with symlinks too), writing_into_the_overlay_leaves_the_base_alone, a_file_is_linked_or_else_copied
(the fallback, with a link that fails) and, on Unix, a_symlink_file_is_copied_through.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

None: Horizon's own content-mod root, not vanilla behaviour.

Self-check

Rebased on origin/main b9a80d619 (today); after the rebase: cargo test -p horizon-client-lib --lib mod_content 35 passed, the 23 --ignored content-root tests passed, rustfmt and clippy (-D warnings) clean. The full pr_ready run below was on the earlier base.

pr_ready (tools/pr_ready.py --quick on Marian_PC, against origin/main at 406ad19e4, 3 min 8 s)

Check Result
Scope ✅ 2 files, +183 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 612 run, FAILED (failures=14, skipped=2) (1 min 54 s)
rustfmt ✅ (11 s)
clippy ✅ (15 s)
tests: horizon-client-lib ✅ 1437 passed (41 s)
doc tests ✅ 0 passed (1 s)
content root tests ✅ 23 passed
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The Python tests' 14 failures are all in tests/test_pre_push.py and fail the same way on a clean origin/main (406ad19e4) on this Windows machine (the pre-push hook tests); nothing in this branch touches Python or the hooks. The 23 content-root tests (the 4 #[ignore]d slow ones among them) pass: content root tests ✅ 23 passed.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/7265 **Author:** [@mmmaarian03-crypto](https://github.com/mmmaarian03-crypto) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/windows-content-hardlinks` --- ### 📝 Commits (1) - [`7bd3ccc`](https://github.com/horizon-rust/horizon/commit/7bd3ccc656b0f985ec76022f4923e159f96f33c5) Content root: hard-link the base files on Windows instead of copying them ### 📊 Changes **2 files changed** (+183 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mod_content.rs` (+18 -1) 📝 `crates/horizon-client/src/mod_content_tests.rs` (+165 -0) </details> ### 📄 Description > 🤖 Opened by Marian's AI agent (Claude), not by Marian himself. ## What and why Fixes #7257. On Windows, `mod_content::link` copies every file of the prepared resource root into the content root (`.horizon-cache/mod-content`) when a content mod is on; on Unix it makes a symlink. That is ~28,000 files and 0.6 GiB written again on every rebuild, and the root is rebuilt after every update, because its stamp holds the executable's path, size and date. This makes the Windows `link` of a file a **hard link** (`std::fs::hard_link`, no privilege needed on NTFS), and falls back to the copy when no link can be made: another volume, a filesystem without links, the NTFS limit of 1023 links to a file. A symlink in the base is still copied through, as `fs::copy` always did. Nothing else changes: the walk, the errors and the Unix side are the same, and the resulting root is byte-identical. It is what the resource-pack overlay's `link` in `packs.rs` already does; this is the same change for the content root, which still copies. | step of a rebuild, replayed on disk (28,177 base files, 251 rewritten tables, 116,244 mod files; NVMe, Defender on) | copy | hard link | |---|---|---| | the base: copied / linked | 22.9 · 34.1 · 16.5 s | 9.7 · 8.9 · 7.1 s | | everything `build` does to files (base, tables, mod files) | 60.8 – 110.5 s | 52.7 – 59.1 s | Three runs each, order alternated, measured on the earlier base `8a7cd0dea`. The replay writes random bytes with the sizes of a real 76-mod pack's root, so it measures file operations only, not the JSON work. The real `build()` on a prepared root with one small mod (the ignored `content_root_is_reused_until_a_mod_changes`: one build and one rebuild) took 37.0 / 40.7 s with copies and 23.9 / 22.2 s with links, same volume. **Why it is safe.** A hard link shares the base file's data, so an in-place write into the root would write into the base. The root is never written in place: `Overlay::write` removes the name and then writes, `out_path` is only read, the stamp is a file of the root's own, and the prepared-data file (`horizon_core::prepared_files::write`) is written through a temporary file renamed into place, and `link_children` already leaves it out. The rest of the game only reads the root, except the sprite cache, which also writes a temporary file and renames it over the name. I looked for `fs::write`, `File::create` and `OpenOptions` on resource paths: tests only besides those. `horizon-prepare`'s "never hard links" note is about the copies the exporters write into the prepared root, which this does not touch. **Not in this PR.** - The stamp. It is what stops a rebuilt game from serving a root made by older code; reusing it across updates needs a content identity of the code that builds the root, a maintainers' decision. - Directory junctions, as `packs.rs` makes for untouched directories: `Overlay::dir` replaces a symlinked directory with `remove_file`, which Windows refuses for a junction, so it is a bigger change. Tests: `the_overlay_shares_the_base_files` (fails on the copy: the base file is edited in place and must show in the root; runs on Unix with symlinks too), `writing_into_the_overlay_leaves_the_base_alone`, `a_file_is_linked_or_else_copied` (the fallback, with a link that fails) and, on Unix, `a_symlink_file_is_copied_through`. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [x] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference None: Horizon's own content-mod root, not vanilla behaviour. ## Self-check Rebased on origin/main b9a80d619 (today); after the rebase: `cargo test -p horizon-client-lib --lib mod_content` 35 passed, the 23 `--ignored` content-root tests passed, rustfmt and clippy (`-D warnings`) clean. The full **pr_ready** run below was on the earlier base. **pr_ready** (`tools/pr_ready.py --quick` on Marian_PC, against origin/main at 406ad19e4, 3 min 8 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +183 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 612 run, FAILED (failures=14, skipped=2) (1 min 54 s) | | rustfmt | ✅ (11 s) | | clippy | ✅ (15 s) | | tests: horizon-client-lib | ✅ 1437 passed (41 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ✅ 23 passed | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The Python tests' 14 failures are all in `tests/test_pre_push.py` and fail the same way on a clean origin/main (406ad19e4) on this Windows machine (the pre-push hook tests); nothing in this branch touches Python or the hooks. The 23 content-root tests (the 4 `#[ignore]`d slow ones among them) pass: `content root tests ✅ 23 passed`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:39:44 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#7452
No description provided.