Skip to content

Continue inventory scanning and track inaccessible directories instead of failing #229

@paul-fresquet

Description

@paul-fresquet

Problem

Currently, when scanning directories during inventory, if an exception is thrown when accessing a directory (e.g., UnauthorizedAccessException when accessing protected system directories like C:\Windows, the entire inventory process fails and stops.

This prevents the inventory from completing even though other accessible directories could still be scanned. In a typical use case, users should be able to inventory directories like C:\Windows\ without administrator privileges, skipping inaccessible subdirectories.

Current Behavior

  • When DirectoryInfo.GetDirectories() or GetFiles() encounters an inaccessible directory/file, exceptions (UnauthorizedAccessException, DirectoryNotFoundException, or IOException) are thrown
  • The exception propagates up and causes the entire inventory to fail
  • All inventory parts are aborted, even if other paths are accessible

Expected Behavior

The inventory should continue scanning accessible directories while:

  1. Logging inaccessible directories as warnings (without stopping the inventory)
  2. Tracking inaccessible directories in the inventory data structure so they are marked and excluded from synchronization operations
  3. Handling multiple exception types: UnauthorizedAccessException, DirectoryNotFoundException, and IOException

This ensures that:

  • The inventory completes successfully for all accessible paths
  • Inaccessible directories are explicitly recorded and will be skipped during synchronization
  • No incomplete or failed inventories occur due to permission issues

Technical Details

  • Location: InventoryBuilder.DoAnalyze() method (lines 268 and 288)
  • Exceptions to handle:
    • System.UnauthorizedAccessException
    • System.IO.DirectoryNotFoundException
    • System.IO.IOException
  • Affected operations: DirectoryInfo.GetDirectories() and GetFiles()
  • Common scenario: Scanning C:\Windows\ without administrator privileges

Implementation Notes

  • Wrap GetDirectories() and GetFiles() calls in try-catch blocks
  • Log exceptions as warnings (not errors) with appropriate context
  • Mark inaccessible directories in the inventory structure (need to design the data model for this)
  • Ensure that the synchronization workflow can identify and skip these tracked inaccessible directories

Related Code

  • src/ByteSync.Client/Services/Inventories/InventoryBuilder.cs (lines 268, 288)
  • src/ByteSync.Client/Services/Inventories/BaseInventoryRunner.cs
  • Consider impact on \InventoryPart\ and related data models to track inaccessible paths

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions