commit d457919ff56d9b2044cb9064dd12a32481b656bf (tree)
parent 05edfe983ce59c1fe1b1c652065651714ce59c52
Author: LeRoyce Pearson <leroycepearson@geemili.xyz>
Date: Tue, 14 Apr 2020 21:27:20 -0600
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()`.
Diffstat:
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git 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);
}