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.master
parent
8c77c5705f
commit
148fe2e999
|
@ -441,18 +441,13 @@ static Error write_manifest_file(CacheHash *ch) {
|
|||
}
|
||||
|
||||
Error cache_final(CacheHash *ch, Buf *out_digest) {
|
||||
Error err;
|
||||
|
||||
assert(ch->manifest_file_path != nullptr);
|
||||
|
||||
if (ch->manifest_dirty) {
|
||||
if ((err = write_manifest_file(ch))) {
|
||||
fprintf(stderr, "Warning: Unable to write cache file '%s': %s\n",
|
||||
buf_ptr(ch->manifest_file_path), err_str(err));
|
||||
}
|
||||
}
|
||||
// We don't close the manifest file yet, because we want to
|
||||
// keep it locked until the API user is done using it.
|
||||
// We also don't write out the manifest yet, because until
|
||||
// cache_release is called we still might be working on creating
|
||||
// the artifacts to cache.
|
||||
|
||||
uint8_t bin_digest[48];
|
||||
int rc = blake2b_final(&ch->blake, bin_digest, 48);
|
||||
|
@ -465,5 +460,15 @@ Error cache_final(CacheHash *ch, Buf *out_digest) {
|
|||
|
||||
void cache_release(CacheHash *ch) {
|
||||
assert(ch->manifest_file_path != nullptr);
|
||||
|
||||
Error err;
|
||||
|
||||
if (ch->manifest_dirty) {
|
||||
if ((err = write_manifest_file(ch))) {
|
||||
fprintf(stderr, "Warning: Unable to write cache file '%s': %s\n",
|
||||
buf_ptr(ch->manifest_file_path), err_str(err));
|
||||
}
|
||||
}
|
||||
|
||||
os_file_close(ch->manifest_file);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue