bug: open_next_directory returns 0 for both empty queue and opendir failure #38

Closed
opened 2026-07-20 14:58:26 +02:00 by TapTap · 0 comments
Owner

In src/client/scanner.c, the open_next_directory() function returns 0 for two very different conditions:

Lines 58-77:

static int open_next_directory(DirectoryScanner* scanner) {
    ...
    if (queue_is_empty(scanner->directories))
        return 0;  // CASE 1: No more directories to scan

    scanner->current_path = (char*)queue_dequeue(scanner->directories);
    scanner->current_dir = opendir(scanner->current_path);
    if (scanner->current_dir == NULL) {
        perror("Could not open directory");
        free(scanner->current_path);
        scanner->current_path = NULL;
        return 0;  // CASE 2: opendir failed
    }
    return 1;
}

When opendir() fails (e.g., permission denied on a subdirectory), the code silently drops the directory from the queue and continues. This means:

  • Files inside unreadable directories are silently skipped
  • No error is propagated to the user beyond the perror() call
  • The scanner will not retry or report the failure

Suggested Fix: Return distinct error codes (-1 for errors) and log warnings. Consider collecting and reporting inaccessible directories.

Severity: medium

In `src/client/scanner.c`, the `open_next_directory()` function returns `0` for two very different conditions: **Lines 58-77:** ```c static int open_next_directory(DirectoryScanner* scanner) { ... if (queue_is_empty(scanner->directories)) return 0; // CASE 1: No more directories to scan scanner->current_path = (char*)queue_dequeue(scanner->directories); scanner->current_dir = opendir(scanner->current_path); if (scanner->current_dir == NULL) { perror("Could not open directory"); free(scanner->current_path); scanner->current_path = NULL; return 0; // CASE 2: opendir failed } return 1; } ``` When `opendir()` fails (e.g., permission denied on a subdirectory), the code silently drops the directory from the queue and continues. This means: - Files inside unreadable directories are silently skipped - No error is propagated to the user beyond the `perror()` call - The scanner will not retry or report the failure **Suggested Fix:** Return distinct error codes (-1 for errors) and log warnings. Consider collecting and reporting inaccessible directories. **Severity:** medium
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#38