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...@@ -1386,7 +1386,6 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource.Git) anyerror!U
1386 defer pack_file.close();1386 defer pack_file.close();
1387 var fifo = std.fifo.LinearFifo(u8, .{ .Static = 4096 }).init();1387 var fifo = std.fifo.LinearFifo(u8, .{ .Static = 4096 }).init();
1388 try fifo.pump(resource.fetch_stream.reader(), pack_file.deprecatedWriter());1388 try fifo.pump(resource.fetch_stream.reader(), pack_file.deprecatedWriter());
1389 try pack_file.sync();
13901389
1391 var index_file = try pack_dir.createFile("pkg.idx", .{ .read = true });1390 var index_file = try pack_dir.createFile("pkg.idx", .{ .read = true });
1392 defer index_file.close();1391 defer index_file.close();
...@@ -1396,7 +1395,6 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource.Git) anyerror!U...@@ -1396,7 +1395,6 @@ fn unpackGitPack(f: *Fetch, out_dir: fs.Dir, resource: *Resource.Git) anyerror!U
1396 var index_buffered_writer = std.io.bufferedWriter(index_file.deprecatedWriter());1395 var index_buffered_writer = std.io.bufferedWriter(index_file.deprecatedWriter());
1397 try git.indexPack(gpa, object_format, pack_file, index_buffered_writer.writer());1396 try git.indexPack(gpa, object_format, pack_file, index_buffered_writer.writer());
1398 try index_buffered_writer.flush();1397 try index_buffered_writer.flush();
1399 try index_file.sync();
1400 }1398 }
14011399
1402 {1400 {
src/Package/Fetch/git.zig-2
...@@ -238,7 +238,6 @@ pub const Repository = struct {...@@ -238,7 +238,6 @@ pub const Repository = struct {
238 };238 };
239 defer file.close();239 defer file.close();
240 try file.writeAll(file_object.data);240 try file.writeAll(file_object.data);
241 try file.sync();
242 },241 },
243 .symlink => {242 .symlink => {
244 try repository.odb.seekOid(entry.oid);243 try repository.odb.seekOid(entry.oid);
...@@ -1690,7 +1689,6 @@ pub fn main() !void {...@@ -1690,7 +1689,6 @@ pub fn main() !void {
1690 var index_buffered_writer = std.io.bufferedWriter(index_file.deprecatedWriter());1689 var index_buffered_writer = std.io.bufferedWriter(index_file.deprecatedWriter());
1691 try indexPack(allocator, format, pack_file, index_buffered_writer.writer());1690 try indexPack(allocator, format, pack_file, index_buffered_writer.writer());
1692 try index_buffered_writer.flush();1691 try index_buffered_writer.flush();
1693 try index_file.sync();
16941692
1695 std.debug.print("Starting checkout...\n", .{});1693 std.debug.print("Starting checkout...\n", .{});
1696 var repository = try Repository.init(allocator, format, pack_file, index_file);1694 var repository = try Repository.init(allocator, format, pack_file, index_file);