authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-15 13:21:36+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-18 17:10:04+01:00
logd32829e053af2a0f382d4d692ede85c176c9f803
tree1b85e5aa9e44648f78a0aa56110cff226136f5a8
parenta0792e743ff41cf17343fad02bde54240df89419
signaturelock-open Commit is signed but in an unrecognized format.

std.Build.Cache: change contract of `addFilePostContents`

This function was broken, because it took ownership of the buffer on error *sometimes*, in a way which the caller could not tell. Rather than trying to be clever, it's easier to just follow the same interface as all other `addFilePost` methods, and not take ownership of the path. This is a breaking change. The next commits will apply it to the compiler, which is the only user of this function in the ziglang/zig repository.

1 files changed, 2 insertions(+), 3 deletions(-)

lib/std/Build/Cache.zig+2-3
......@@ -1011,17 +1011,16 @@ pub const Manifest = struct {
10111011 }
10121012
10131013 /// Like `addFilePost` but when the file contents have already been loaded from disk.
1014 /// On success, cache takes ownership of `resolved_path`.
10151014 pub fn addFilePostContents(
10161015 self: *Manifest,
1017 resolved_path: []u8,
1016 file_path: []const u8,
10181017 bytes: []const u8,
10191018 stat: File.Stat,
10201019 ) !void {
10211020 assert(self.manifest_file != null);
10221021 const gpa = self.cache.gpa;
10231022
1024 const prefixed_path = try self.cache.findPrefixResolved(resolved_path);
1023 const prefixed_path = try self.cache.findPrefix(file_path);
10251024 errdefer gpa.free(prefixed_path.sub_path);
10261025
10271026 const gop = try self.files.getOrPutAdapted(gpa, prefixed_path, FilesAdapter{});