Updated amduat_asl_store_fs_put_impl so fsync failure cleanup only unlinks when this call actually created the object, preventing deletion of pre-existing mappings. Change is in asl_store_fs.c.

This commit is contained in:
Carl Niklas Rydberg 2025-12-21 22:49:24 +01:00
parent 8e26d11e3b
commit fe9acea94b

View file

@ -312,6 +312,7 @@ static amduat_asl_store_error_t amduat_asl_store_fs_put_impl(
char *object_path; char *object_path;
amduat_asl_store_error_t cmp_err; amduat_asl_store_error_t cmp_err;
amduat_asl_store_fs_write_status_t write_status; amduat_asl_store_fs_write_status_t write_status;
bool wrote_new;
if (ctx == NULL || out_ref == NULL) { if (ctx == NULL || out_ref == NULL) {
return AMDUAT_ASL_STORE_ERR_INTEGRITY; return AMDUAT_ASL_STORE_ERR_INTEGRITY;
@ -407,6 +408,7 @@ static amduat_asl_store_error_t amduat_asl_store_fs_put_impl(
return cmp_err; return cmp_err;
} }
wrote_new = false;
write_status = amduat_asl_store_fs_write_atomic(level2_path, write_status = amduat_asl_store_fs_write_atomic(level2_path,
object_path, object_path,
artifact_bytes.data, artifact_bytes.data,
@ -436,10 +438,14 @@ static amduat_asl_store_error_t amduat_asl_store_fs_put_impl(
free(level2_path); free(level2_path);
free(object_path); free(object_path);
return AMDUAT_ASL_STORE_ERR_INTEGRITY; return AMDUAT_ASL_STORE_ERR_INTEGRITY;
} else {
wrote_new = true;
} }
if (!amduat_asl_store_fs_fsync_directory(level2_path)) { if (!amduat_asl_store_fs_fsync_directory(level2_path)) {
unlink(object_path); if (wrote_new) {
unlink(object_path);
}
amduat_octets_free(&artifact_bytes); amduat_octets_free(&artifact_bytes);
amduat_reference_free(&derived_ref); amduat_reference_free(&derived_ref);
free(objects_path); free(objects_path);
@ -451,7 +457,9 @@ static amduat_asl_store_error_t amduat_asl_store_fs_put_impl(
return AMDUAT_ASL_STORE_ERR_INTEGRITY; return AMDUAT_ASL_STORE_ERR_INTEGRITY;
} }
if (!amduat_asl_store_fs_fsync_directory(fs->root_path)) { if (!amduat_asl_store_fs_fsync_directory(fs->root_path)) {
unlink(object_path); if (wrote_new) {
unlink(object_path);
}
amduat_octets_free(&artifact_bytes); amduat_octets_free(&artifact_bytes);
amduat_reference_free(&derived_ref); amduat_reference_free(&derived_ref);
free(objects_path); free(objects_path);