Skip to content

Commit a2f265f

Browse files
hsbtclaude
andcommitted
Write vendored compact_index files atomically
The completeness check skips the download once every expected file exists, but File.write truncates before writing, so an install interrupted partway leaves a half-written file in place. A later run would see it, treat the vendor tree as complete, and load a truncated source. Download each file to a sibling .tmp path and rename it into place. The rename stays within the vendor tree, so it is atomic and a target file is only ever observed fully written. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0365a17 commit a2f265f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

spec/support/rubygems_ext.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ def install_vendored_compact_index
110110
url = "https://raw.githubusercontent.com/rubygems/rubygems.org/#{ref}/#{path}"
111111
target = target_root.join(path)
112112
FileUtils.mkdir_p(File.dirname(target))
113-
File.write(target, URI.parse(url).open(&:read))
113+
tmp = "#{target}.tmp"
114+
File.write(tmp, URI.parse(url).open(&:read))
115+
File.rename(tmp, target)
114116
end
115117
end
116118
end

0 commit comments

Comments
 (0)