authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-18 15:31:22-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-18 15:35:03-04:00
log148fe2e99970ca880a8e10ded5af308e28bbc342
tree0101a3deeb5374ca34dc33dfe4ad81b63033e51d
parent8c77c5705f41e55a5f2d80db20270d0c644338ed
signaturelock-open Commit is signed but in an unrecognized format.

stage1 caching: don't write manifest until cache release

this prevents the situation where we determine the cache manifest and write it, but then crash or otherwise error out before putting the artifacts in the proper place. now the artifacts will be in place because cache_release happens after that step is done.

1 files changed, 13 insertions(+), 8 deletions(-)

src/cache_hash.cpp+13-8
...@@ -441,18 +441,13 @@ static Error write_manifest_file(CacheHash *ch) {...@@ -441,18 +441,13 @@ static Error write_manifest_file(CacheHash *ch) {
441}441}
442442
443Error cache_final(CacheHash *ch, Buf *out_digest) {443Error cache_final(CacheHash *ch, Buf *out_digest) {
444 Error err;
445
446 assert(ch->manifest_file_path != nullptr);444 assert(ch->manifest_file_path != nullptr);
447445
448 if (ch->manifest_dirty) {
449 if ((err = write_manifest_file(ch))) {
450 fprintf(stderr, "Warning: Unable to write cache file '%s': %s\n",
451 buf_ptr(ch->manifest_file_path), err_str(err));
452 }
453 }
454 // We don't close the manifest file yet, because we want to446 // We don't close the manifest file yet, because we want to
455 // keep it locked until the API user is done using it.447 // keep it locked until the API user is done using it.
448 // We also don't write out the manifest yet, because until
449 // cache_release is called we still might be working on creating
450 // the artifacts to cache.
456451
457 uint8_t bin_digest[48];452 uint8_t bin_digest[48];
458 int rc = blake2b_final(&ch->blake, bin_digest, 48);453 int rc = blake2b_final(&ch->blake, bin_digest, 48);
...@@ -465,5 +460,15 @@ Error cache_final(CacheHash *ch, Buf *out_digest) {...@@ -465,5 +460,15 @@ Error cache_final(CacheHash *ch, Buf *out_digest) {
465460
466void cache_release(CacheHash *ch) {461void cache_release(CacheHash *ch) {
467 assert(ch->manifest_file_path != nullptr);462 assert(ch->manifest_file_path != nullptr);
463
464 Error err;
465
466 if (ch->manifest_dirty) {
467 if ((err = write_manifest_file(ch))) {
468 fprintf(stderr, "Warning: Unable to write cache file '%s': %s\n",
469 buf_ptr(ch->manifest_file_path), err_str(err));
470 }
471 }
472
468 os_file_close(ch->manifest_file);473 os_file_close(ch->manifest_file);
469}474}