diff --git a/src/adapters/asl_derivation_index_fs/asl_derivation_index_fs.c b/src/adapters/asl_derivation_index_fs/asl_derivation_index_fs.c index 3ce0c64..3f374bc 100644 --- a/src/adapters/asl_derivation_index_fs/asl_derivation_index_fs.c +++ b/src/adapters/asl_derivation_index_fs/asl_derivation_index_fs.c @@ -638,21 +638,13 @@ amduat_asl_store_error_t amduat_asl_derivation_index_fs_add( } *dir_c = '\0'; - if (!amduat_asl_derivation_ensure_directory(artifact_dir) || - !amduat_asl_derivation_ensure_directory(dir_b) || - !amduat_asl_derivation_ensure_directory(dir_a)) { - free(path); - free(dir_a); - free(dir_b); - free(artifact_dir); - free(artifact_hex); - return AMDUAT_ASL_STORE_ERR_IO; - } - { + char *index_path = NULL; char *derivations_path = NULL; char *by_artifact_path = NULL; - if (!amduat_asl_derivation_build_derivations_path(index->root_path, + if (!amduat_asl_derivation_join_path(index->root_path, "index", + &index_path) || + !amduat_asl_derivation_build_derivations_path(index->root_path, &derivations_path)) { free(path); free(dir_a); @@ -661,7 +653,9 @@ amduat_asl_store_error_t amduat_asl_derivation_index_fs_add( free(artifact_hex); return AMDUAT_ASL_STORE_ERR_IO; } - if (!amduat_asl_derivation_ensure_directory(derivations_path)) { + if (!amduat_asl_derivation_ensure_directory(index_path) || + !amduat_asl_derivation_ensure_directory(derivations_path)) { + free(index_path); free(derivations_path); free(path); free(dir_a); @@ -672,6 +666,7 @@ amduat_asl_store_error_t amduat_asl_derivation_index_fs_add( } if (!amduat_asl_derivation_join_path(derivations_path, "by_artifact", &by_artifact_path)) { + free(index_path); free(derivations_path); free(path); free(dir_a); @@ -682,6 +677,7 @@ amduat_asl_store_error_t amduat_asl_derivation_index_fs_add( } if (!amduat_asl_derivation_ensure_directory(by_artifact_path)) { free(by_artifact_path); + free(index_path); free(derivations_path); free(path); free(dir_a); @@ -691,9 +687,20 @@ amduat_asl_store_error_t amduat_asl_derivation_index_fs_add( return AMDUAT_ASL_STORE_ERR_IO; } free(by_artifact_path); + free(index_path); free(derivations_path); } + if (!amduat_asl_derivation_ensure_directory(dir_b) || + !amduat_asl_derivation_ensure_directory(dir_a)) { + free(path); + free(dir_a); + free(dir_b); + free(artifact_dir); + free(artifact_hex); + return AMDUAT_ASL_STORE_ERR_IO; + } + err = amduat_asl_derivation_open_records_file(path, &fp); if (err != AMDUAT_ASL_STORE_OK) { free(path); diff --git a/tests/asl/test_asl_derivation_index_fs.c b/tests/asl/test_asl_derivation_index_fs.c index 6ff073d..d45d75d 100644 --- a/tests/asl/test_asl_derivation_index_fs.c +++ b/tests/asl/test_asl_derivation_index_fs.c @@ -71,7 +71,7 @@ static amduat_reference_t make_ref(uint8_t seed, size_t len) { for (size_t i = 0; i < len; ++i) { bytes[i] = (uint8_t)(seed + i); } - return amduat_reference(0x0001u, amduat_octets(bytes, len)); + return amduat_reference(0x1234u, amduat_octets(bytes, len)); } static int test_round_trip(void) { @@ -116,15 +116,21 @@ static int test_round_trip(void) { record2.has_params_ref = false; record2.has_exec_profile = false; - if (amduat_asl_derivation_index_fs_add(&index, artifact_ref, &record) != - AMDUAT_ASL_STORE_OK) { - fprintf(stderr, "add record failed\n"); - goto cleanup_records; + { + amduat_asl_store_error_t err = + amduat_asl_derivation_index_fs_add(&index, artifact_ref, &record); + if (err != AMDUAT_ASL_STORE_OK) { + fprintf(stderr, "add record failed: %d\n", err); + goto cleanup_records; + } } - if (amduat_asl_derivation_index_fs_add(&index, artifact_ref, &record2) != - AMDUAT_ASL_STORE_OK) { - fprintf(stderr, "add record2 failed\n"); - goto cleanup_records; + { + amduat_asl_store_error_t err = + amduat_asl_derivation_index_fs_add(&index, artifact_ref, &record2); + if (err != AMDUAT_ASL_STORE_OK) { + fprintf(stderr, "add record2 failed: %d\n", err); + goto cleanup_records; + } } if (amduat_asl_derivation_index_fs_list(&index,