Skip to content

[refactor] Centralize filesystem entry classification in inventory flow#276

Open
paul-fresquet wants to merge 1 commit intomasterfrom
feature/263-classify-entry-inspector
Open

[refactor] Centralize filesystem entry classification in inventory flow#276
paul-fresquet wants to merge 1 commit intomasterfrom
feature/263-classify-entry-inspector

Conversation

@paul-fresquet
Copy link
Contributor

Summary:

  • Centralize file system entry type detection behind IFileSystemInspector with a new ClassifyEntry(FileSystemInfo) method.
  • Keep FileSystemEntryKind in the client layer (no move to Common) and preserve existing inventory behavior.

Key changes:

  • Added ClassifyEntry to IFileSystemInspector and implemented it in FileSystemInspector.
  • Implemented classification order: symlink detection (LinkTarget + ReparsePoint fallback), POSIX classification (Linux/macOS), then Directory/RegularFile fallback, then Unknown.
  • Refactored InventoryBuilder to use FileSystemInspector.ClassifyEntry instead of scattered symlink/POSIX checks.
  • Updated InventoryBuilderInspectorTests to the new centralized classifier contract.
  • Added FileSystemInspectorTests to cover standard classification and edge behavior.

Notes/risks:

  • Existing boolean inspector methods remain functional (non-breaking intent).
  • Local targeted inventory unit tests are green after refactor.
  • Full solution tests still show a pre-existing failure in ByteSync.Functions.IntegrationTests end-to-end setup (outside this change scope).

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 7, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the inventory-building flow to centralize filesystem entry type detection behind IFileSystemInspector.ClassifyEntry(FileSystemInfo), consolidating symlink and POSIX-type handling so InventoryBuilder no longer performs scattered checks.

Changes:

  • Added ClassifyEntry(FileSystemInfo) to IFileSystemInspector and implemented it in FileSystemInspector (symlink → POSIX → dir/file fallback → unknown).
  • Refactored InventoryBuilder to use FileSystemInspector.ClassifyEntry(...) for skip decisions (symlink + POSIX special files).
  • Updated/added unit tests: refactored InventoryBuilderInspectorTests mocks and introduced FileSystemInspectorTests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/ByteSync.Client.UnitTests/Services/Inventories/InventoryBuilderInspectorTests.cs Updates mocks to support the new ClassifyEntry contract and adjusts skip-path tests accordingly.
tests/ByteSync.Client.UnitTests/Services/Inventories/FileSystemInspectorTests.cs Adds coverage for the new centralized classification logic (directory/file/symlink/POSIX special/null).
src/ByteSync.Client/Services/Inventories/InventoryBuilder.cs Replaces direct POSIX + reparse-point checks with centralized ClassifyEntry calls and removes now-redundant helper methods.
src/ByteSync.Client/Services/Inventories/FileSystemInspector.cs Implements ClassifyEntry and introduces internal POSIX classifier wiring plus link-target/reparse-point helpers.
src/ByteSync.Client/Interfaces/Controls/Inventories/IFileSystemInspector.cs Extends inspector interface with ClassifyEntry.
Comments suppressed due to low confidence (1)

src/ByteSync.Client/Services/Inventories/InventoryBuilder.cs:406

  • Symlink/reparse-point skips no longer emit any log message (previously IsReparsePoint(...) logged warnings). This reduces observability when inventories unexpectedly skip content. Consider adding a warning/info log when ClassifyEntry(...) returns Symlink (either here or inside the classifier), consistent with other skip reasons.
        var entryKind = FileSystemInspector.ClassifyEntry(fileInfo);
        if (entryKind == FileSystemEntryKind.Symlink)
        {
            RecordSkippedEntry(inventoryPart, fileInfo, SkipReason.Symlink, FileSystemEntryKind.Symlink);
            
            return true;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
catch (Exception)
{
return FileSystemEntryKind.Unknown;
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ClassifyEntry, the POSIX classification catch returns Unknown immediately. That short-circuits the intended fallback to Directory/RegularFile classification and can change behavior if the POSIX classifier throws. Consider swallowing/logging the exception and continuing to the type-based fallback instead of returning early.

Suggested change
return FileSystemEntryKind.Unknown;
// Ignore POSIX classification failures and fall back to type-based classification below.

Copilot uses AI. Check for mistakes.

public interface IFileSystemInspector
{
FileSystemEntryKind ClassifyEntry(FileSystemInfo fsi);
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClassifyEntry defensively handles null inputs, but the interface contract uses a non-nullable FileSystemInfo parameter. With nullable enabled, consider changing the signature to FileSystemInfo? to reflect the supported input and avoid callers needing null! in tests.

Suggested change
FileSystemEntryKind ClassifyEntry(FileSystemInfo fsi);
FileSystemEntryKind ClassifyEntry(FileSystemInfo? fsi);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant