authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-14 21:51:20-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
loge7657f2938e9061a546c5ad726a9575ad6a8eba3
treeebb4559150bb5bf7b169ddb9a7639a93fa4bee3d
parent967b9825a7b57586cd34f51d9b915505ffbd455d

Make `CacheHash.release` return an error

If a user doesn't care that the manifest failed to be written, they can simply ignore it. The program will still work; that particular cache item will simply not be cached.

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

lib/std/cache_hash.zig+14-10
......@@ -311,13 +311,17 @@ pub const CacheHash = struct {
311311 try self.manifest_file.?.writeAll(contents.items);
312312 }
313313
314 pub fn release(self: *@This()) void {
314 /// Releases the manifest file and frees any memory the CacheHash was using.
315 /// `CacheHash.hit` must be called first.
316 ///
317 /// Will also attempt to write to the manifest file if the manifest is dirty.
318 /// Writing to the manifest file is the only way that this file can return an
319 /// error.
320 pub fn release(self: *@This()) !void {
315321 debug.assert(self.manifest_file != null);
316322
317323 if (self.manifest_dirty) {
318 self.write_manifest() catch |err| {
319 debug.warn("Unable to write cache file '{}': {}\n", .{ self.b64_digest, err });
320 };
324 try self.write_manifest();
321325 }
322326
323327 self.manifest_file.?.close();
......@@ -366,7 +370,7 @@ test "cache file and then recall it" {
366370
367371 {
368372 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
369 defer ch.release();
373 defer ch.release() catch unreachable;
370374
371375 ch.add(true);
372376 ch.add(@as(u16, 1234));
......@@ -380,7 +384,7 @@ test "cache file and then recall it" {
380384 }
381385 {
382386 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
383 defer ch.release();
387 defer ch.release() catch unreachable;
384388
385389 ch.add(true);
386390 ch.add(@as(u16, 1234));
......@@ -420,7 +424,7 @@ test "check that changing a file makes cache fail" {
420424
421425 {
422426 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
423 defer ch.release();
427 defer ch.release() catch unreachable;
424428
425429 ch.add("1234");
426430 try ch.addFile(temp_file);
......@@ -435,7 +439,7 @@ test "check that changing a file makes cache fail" {
435439
436440 {
437441 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
438 defer ch.release();
442 defer ch.release() catch unreachable;
439443
440444 ch.add("1234");
441445 try ch.addFile(temp_file);
......@@ -462,7 +466,7 @@ test "no file inputs" {
462466
463467 {
464468 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
465 defer ch.release();
469 defer ch.release() catch unreachable;
466470
467471 ch.add("1234");
468472
......@@ -473,7 +477,7 @@ test "no file inputs" {
473477 }
474478 {
475479 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
476 defer ch.release();
480 defer ch.release() catch unreachable;
477481
478482 ch.add("1234");
479483