authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-14 21:27:20-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
logd457919ff56d9b2044cb9064dd12a32481b656bf
tree7c81a76b44dc67501e20c5c631f79b8500ab09c6
parent05edfe983ce59c1fe1b1c652065651714ce59c52

Make CacheHash cleanup consistent (always call `release`)

Instead of releasing the manifest file when an error occurs, it is only released when when `CacheHash.release` is called. This maps better to what a zig user expects when they do `defer cache_hash.release()`.

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

lib/std/cache_hash.zig+2-10
......@@ -159,8 +159,6 @@ pub const CacheHash = struct {
159159 }
160160
161161 const this_file = fs.cwd().openFile(cache_hash_file.path.?, .{ .read = true }) catch {
162 self.manifest_file.?.close();
163 self.manifest_file = null;
164162 return error.CacheUnavailable;
165163 };
166164 defer this_file.close();
......@@ -213,8 +211,6 @@ pub const CacheHash = struct {
213211 while (idx < input_file_count) : (idx += 1) {
214212 var cache_hash_file = &self.files.items[idx];
215213 const contents = self.populate_file_hash(cache_hash_file) catch |err| {
216 self.manifest_file.?.close();
217 self.manifest_file = null;
218214 return error.CacheUnavailable;
219215 };
220216 }
......@@ -256,12 +252,7 @@ pub const CacheHash = struct {
256252 var cache_hash_file = try self.files.addOne();
257253 cache_hash_file.path = try fs.path.resolve(self.alloc, &[_][]const u8{file_path});
258254
259 const contents = self.populate_file_hash_fetch(otherAlloc, cache_hash_file) catch |err| {
260 self.manifest_file.close();
261 return err;
262 };
263
264 return contents;
255 return try self.populate_file_hash_fetch(otherAlloc, cache_hash_file);
265256 }
266257
267258 /// Add a file as a dependency of process being cached, after the initial hash has been
......@@ -317,6 +308,7 @@ pub const CacheHash = struct {
317308 }
318309
319310 self.manifest_file.?.close();
311
320312 for (self.files.toSlice()) |*file| {
321313 file.deinit(self.alloc);
322314 }