Skip to content

Commit 8b428eb

Browse files
authored
Merge pull request DeusData#2085 from AmirF194/fix/2001-manifest-walk-skip-unreadable-subdir
fix(pipeline): skip an unreadable subdirectory in the control-file walk instead of aborting the whole index
2 parents 5e9f146 + 0a045b5 commit 8b428eb

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎src/pipeline/pipeline_incremental.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,12 @@ static int semantic_manifest_walk_controls(semantic_manifest_builder_t *builder,
426426
if (depth >= MANIFEST_WALK_MAX_DEPTH)
427427
return 0;
428428
cbm_dir_t *dir = cbm_opendir(abs_dir);
429-
if (!dir)
430-
return CBM_NOT_FOUND;
429+
if (!dir) {
430+
/* A nested directory we can't open has no control files to
431+
* contribute; skip it like discover.c's walk_dir already does.
432+
* The root call (depth 0) still fails closed. */
433+
return depth == 0 ? CBM_NOT_FOUND : 0;
434+
}
431435
int rc = 0;
432436
cbm_dirent_t *entry;
433437
while (rc == 0 && (entry = cbm_readdir(dir)) != NULL) {

‎tests/test_pipeline.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8467,6 +8467,45 @@ TEST(pipeline_semantic_manifest_rejects_non_directory_root) {
84678467
PASS();
84688468
}
84698469

8470+
#ifndef _WIN32
8471+
/* A nested directory the process cannot open (permission-denied) must not
8472+
* abort the whole manifest walk: it has no control files to contribute, so
8473+
* it is skipped, and control files in sibling directories still get found.
8474+
* Root-not-a-directory (above) is a different, still fail-closed case. */
8475+
TEST(pipeline_semantic_manifest_skips_unreadable_subdirectory) {
8476+
char tmp[256];
8477+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_manifest_locked_dir_XXXXXX");
8478+
ASSERT_NOT_NULL(cbm_mkdtemp(tmp));
8479+
write_temp_file(tmp, "readable.py", "def Readable():\n return 1\n");
8480+
write_temp_file(tmp, "locked/secret.txt", "should never be opened\n");
8481+
write_temp_file(tmp, "sibling/.gitignore", "*.log\n");
8482+
8483+
char locked_path[512];
8484+
snprintf(locked_path, sizeof(locked_path), "%s/locked", tmp);
8485+
ASSERT_EQ(chmod(locked_path, 0), 0);
8486+
8487+
cbm_file_hash_t *manifest = NULL;
8488+
int manifest_count = -1;
8489+
int rc = cbm_pipeline_build_semantic_manifest("manifest-skip-locked", tmp, NULL, 0, NULL, 0,
8490+
NULL, NULL, &manifest, &manifest_count);
8491+
8492+
bool found_sibling_gitignore = false;
8493+
for (int i = 0; i < manifest_count; i++) {
8494+
if (manifest[i].rel_path && strcmp(manifest[i].rel_path, "sibling/.gitignore") == 0) {
8495+
found_sibling_gitignore = true;
8496+
}
8497+
}
8498+
8499+
chmod(locked_path, 0755);
8500+
cbm_pipeline_free_semantic_manifest(manifest, manifest_count > 0 ? manifest_count : 0);
8501+
th_rmtree(tmp);
8502+
8503+
ASSERT_EQ(rc, 0);
8504+
ASSERT_TRUE(found_sibling_gitignore);
8505+
PASS();
8506+
}
8507+
#endif /* !_WIN32 */
8508+
84708509
/* A fully validated staged graph must be able to recover from a definitely
84718510
* non-SQLite destination without deleting evidence or overwriting an earlier
84728511
* quarantine. The replacement happens only after the corrupt bytes are moved. */
@@ -28610,6 +28649,9 @@ SUITE(pipeline_semantic_manifest_repro) {
2861028649
RUN_TEST(pipeline_incremental_successful_publication_preserves_adr);
2861128650
RUN_TEST(pipeline_full_adr_capture_failure_preserves_previous_generation);
2861228651
RUN_TEST(pipeline_semantic_manifest_rejects_non_directory_root);
28652+
#ifndef _WIN32
28653+
RUN_TEST(pipeline_semantic_manifest_skips_unreadable_subdirectory);
28654+
#endif
2861328655
RUN_TEST(pipeline_full_reindex_quarantines_corrupt_destination_without_overwrite);
2861428656
RUN_TEST(pipeline_full_reindex_replaces_legacy_schema_without_quarantine);
2861528657
#endif

0 commit comments

Comments
 (0)