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