| ... | ... | @@ -311,13 +311,17 @@ pub const CacheHash = struct { |
| 311 | 311 | try self.manifest_file.?.writeAll(contents.items); |
| 312 | 312 | } |
| 313 | 313 | |
| 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 { |
| 315 | 321 | debug.assert(self.manifest_file != null); |
| 316 | 322 | |
| 317 | 323 | 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(); |
| 321 | 325 | } |
| 322 | 326 | |
| 323 | 327 | self.manifest_file.?.close(); |
| ... | ... | @@ -366,7 +370,7 @@ test "cache file and then recall it" { |
| 366 | 370 | |
| 367 | 371 | { |
| 368 | 372 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| 369 | | defer ch.release(); |
| 373 | defer ch.release() catch unreachable; |
| 370 | 374 | |
| 371 | 375 | ch.add(true); |
| 372 | 376 | ch.add(@as(u16, 1234)); |
| ... | ... | @@ -380,7 +384,7 @@ test "cache file and then recall it" { |
| 380 | 384 | } |
| 381 | 385 | { |
| 382 | 386 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| 383 | | defer ch.release(); |
| 387 | defer ch.release() catch unreachable; |
| 384 | 388 | |
| 385 | 389 | ch.add(true); |
| 386 | 390 | ch.add(@as(u16, 1234)); |
| ... | ... | @@ -420,7 +424,7 @@ test "check that changing a file makes cache fail" { |
| 420 | 424 | |
| 421 | 425 | { |
| 422 | 426 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| 423 | | defer ch.release(); |
| 427 | defer ch.release() catch unreachable; |
| 424 | 428 | |
| 425 | 429 | ch.add("1234"); |
| 426 | 430 | try ch.addFile(temp_file); |
| ... | ... | @@ -435,7 +439,7 @@ test "check that changing a file makes cache fail" { |
| 435 | 439 | |
| 436 | 440 | { |
| 437 | 441 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| 438 | | defer ch.release(); |
| 442 | defer ch.release() catch unreachable; |
| 439 | 443 | |
| 440 | 444 | ch.add("1234"); |
| 441 | 445 | try ch.addFile(temp_file); |
| ... | ... | @@ -462,7 +466,7 @@ test "no file inputs" { |
| 462 | 466 | |
| 463 | 467 | { |
| 464 | 468 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| 465 | | defer ch.release(); |
| 469 | defer ch.release() catch unreachable; |
| 466 | 470 | |
| 467 | 471 | ch.add("1234"); |
| 468 | 472 | |
| ... | ... | @@ -473,7 +477,7 @@ test "no file inputs" { |
| 473 | 477 | } |
| 474 | 478 | { |
| 475 | 479 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| 476 | | defer ch.release(); |
| 480 | defer ch.release() catch unreachable; |
| 477 | 481 | |
| 478 | 482 | ch.add("1234"); |
| 479 | 483 | |