Skip to content

Reserve the name with an exclusive create when hard links are unavailable (#1503) - #1580

Merged
echelon merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-1503
Oct 14, 2026
Merged

echelon merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-1503

Conversation

@MarekSpodBiedry

Copy link
Copy Markdown
Contributor

Fixes #1503.

safe_file::publish_new gives a finished temp file its final name without replacing anything. It uses a hard link, which fails on a taken name. On volumes without hard links (FAT/exFAT, some shares) it fell back to "check that the name is free, then fs::rename". rename replaces an existing file, so a file that another writer created between the check and the rename was overwritten. This affects write_new / write_new_unique, which DNG conversion (Convert / Copy as DNG) and merges use.

Fix (fallback path only; the hard-link path is unchanged): the fallback now claims the name with OpenOptions::create_new (atomic, fails with AlreadyExists on a taken name). Then it renames the complete temp file over its own empty placeholder. A failed claim returns AlreadyExists, so write_new_unique tries the next candidate name as before. If the rename fails, the placeholder is removed. The temp file is cleaned up by the existing code in write_new_unique. The module docs describe the new fallback.

Test: fallback_publish_never_replaces_a_file_that_appears_at_the_same_time calls the fallback directly (on the volumes CI uses, hard links always work). A hook makes a competing file appear right before the step that takes the name. The publish must fail with AlreadyExists and the other file must keep its content. Once the name is free, the publish succeeds and the temp file is gone. With the old check-then-rename, the same hook placed before the rename lets the other file be replaced.

@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you @MarekSpodBiedry! This landed on main in integration batch 35 (#1682).

If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there.

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.

No-replace DNG publication can overwrite a concurrent destination when hard links fail

2 participants