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 {...@@ -159,8 +159,6 @@ pub const CacheHash = struct {
159 }159 }
160160
161 const this_file = fs.cwd().openFile(cache_hash_file.path.?, .{ .read = true }) catch {161 const this_file = fs.cwd().openFile(cache_hash_file.path.?, .{ .read = true }) catch {
162 self.manifest_file.?.close();
163 self.manifest_file = null;
164 return error.CacheUnavailable;162 return error.CacheUnavailable;
165 };163 };
166 defer this_file.close();164 defer this_file.close();
...@@ -213,8 +211,6 @@ pub const CacheHash = struct {...@@ -213,8 +211,6 @@ pub const CacheHash = struct {
213 while (idx < input_file_count) : (idx += 1) {211 while (idx < input_file_count) : (idx += 1) {
214 var cache_hash_file = &self.files.items[idx];212 var cache_hash_file = &self.files.items[idx];
215 const contents = self.populate_file_hash(cache_hash_file) catch |err| {213 const contents = self.populate_file_hash(cache_hash_file) catch |err| {
216 self.manifest_file.?.close();
217 self.manifest_file = null;
218 return error.CacheUnavailable;214 return error.CacheUnavailable;
219 };215 };
220 }216 }
...@@ -256,12 +252,7 @@ pub const CacheHash = struct {...@@ -256,12 +252,7 @@ pub const CacheHash = struct {
256 var cache_hash_file = try self.files.addOne();252 var cache_hash_file = try self.files.addOne();
257 cache_hash_file.path = try fs.path.resolve(self.alloc, &[_][]const u8{file_path});253 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| {255 return try self.populate_file_hash_fetch(otherAlloc, cache_hash_file);
260 self.manifest_file.close();
261 return err;
262 };
263
264 return contents;
265 }256 }
266257
267 /// Add a file as a dependency of process being cached, after the initial hash has been258 /// Add a file as a dependency of process being cached, after the initial hash has been
...@@ -317,6 +308,7 @@ pub const CacheHash = struct {...@@ -317,6 +308,7 @@ pub const CacheHash = struct {
317 }308 }
318309
319 self.manifest_file.?.close();310 self.manifest_file.?.close();
311
320 for (self.files.toSlice()) |*file| {312 for (self.files.toSlice()) |*file| {
321 file.deinit(self.alloc);313 file.deinit(self.alloc);
322 }314 }