authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-30 10:00:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-31 08:59:56-07:00
log627a292a1139c96f5de80084ab5ce8b852db5132
tree581042caea1a1957a8df5f2b85a8662b32c3cdaf
parent1a15fbe9607c74096c875f6d871213c7d4db1483

fetch: remove calls to fsync

fsync blocks until the contents have been actually written to disk, which would be useful if we didn't want to report success until having achieved durability. But the OS will ensure coherency; i.e. if one process writes stuff without calling fsync, then another process reads that stuff, the writes will be seen even if they didn't get flushed to disk yet. Since this code deals with ephemeral cache data, it's not worth trying to achieve this kind of durability guarantee. This is consistent with all the other tooling on the system. Certainly, if we wanted to change our stance on this, it would not be something that affects only the git fetching logic.

2 files changed, 0 insertions(+), 4 deletions(-)

src/Package/Fetch.zig-2
......@@ -1386,7 +1386,6 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource.Git) anyerror!U
13861386 defer pack_file.close();
13871387 var fifo = std.fifo.LinearFifo(u8, .{ .Static = 4096 }).init();
13881388 try fifo.pump(resource.fetch_stream.reader(), pack_file.deprecatedWriter());
1389 try pack_file.sync();
13901389
13911390 var index_file = try pack_dir.createFile("pkg.idx", .{ .read = true });
13921391 defer index_file.close();
......@@ -1396,7 +1395,6 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource.Git) anyerror!U
13961395 var index_buffered_writer = std.io.bufferedWriter(index_file.deprecatedWriter());
13971396 try git.indexPack(gpa, object_format, pack_file, index_buffered_writer.writer());
13981397 try index_buffered_writer.flush();
1399 try index_file.sync();
14001398 }
14011399
14021400 {
src/Package/Fetch/git.zig-2
......@@ -238,7 +238,6 @@ pub const Repository = struct {
238238 };
239239 defer file.close();
240240 try file.writeAll(file_object.data);
241 try file.sync();
242241 },
243242 .symlink => {
244243 try repository.odb.seekOid(entry.oid);
......@@ -1690,7 +1689,6 @@ pub fn main() !void {
16901689 var index_buffered_writer = std.io.bufferedWriter(index_file.deprecatedWriter());
16911690 try indexPack(allocator, format, pack_file, index_buffered_writer.writer());
16921691 try index_buffered_writer.flush();
1693 try index_file.sync();
16941692
16951693 std.debug.print("Starting checkout...\n", .{});
16961694 var repository = try Repository.init(allocator, format, pack_file, index_file);