From d457919ff56d9b2044cb9064dd12a32481b656bf Mon Sep 17 00:00:00 2001 From: LeRoyce Pearson Date: Tue, 14 Apr 2020 21:27:20 -0600 Subject: [PATCH] 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()`. --- lib/std/cache_hash.zig | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/std/cache_hash.zig b/lib/std/cache_hash.zig index b00f11c272..d44e3e2d73 100644 --- a/lib/std/cache_hash.zig +++ b/lib/std/cache_hash.zig @@ -159,8 +159,6 @@ pub const CacheHash = struct { } const this_file = fs.cwd().openFile(cache_hash_file.path.?, .{ .read = true }) catch { - self.manifest_file.?.close(); - self.manifest_file = null; return error.CacheUnavailable; }; defer this_file.close(); @@ -213,8 +211,6 @@ pub const CacheHash = struct { while (idx < input_file_count) : (idx += 1) { var cache_hash_file = &self.files.items[idx]; const contents = self.populate_file_hash(cache_hash_file) catch |err| { - self.manifest_file.?.close(); - self.manifest_file = null; return error.CacheUnavailable; }; } @@ -256,12 +252,7 @@ pub const CacheHash = struct { var cache_hash_file = try self.files.addOne(); cache_hash_file.path = try fs.path.resolve(self.alloc, &[_][]const u8{file_path}); - const contents = self.populate_file_hash_fetch(otherAlloc, cache_hash_file) catch |err| { - self.manifest_file.close(); - return err; - }; - - return contents; + return try self.populate_file_hash_fetch(otherAlloc, cache_hash_file); } /// Add a file as a dependency of process being cached, after the initial hash has been @@ -317,6 +308,7 @@ pub const CacheHash = struct { } self.manifest_file.?.close(); + for (self.files.toSlice()) |*file| { file.deinit(self.alloc); }