Skip to content

[FileSystem] Bug: Caching IFileInfo, recreating it, will result in stale cache #816

@pw-sgr

Description

@pw-sgr

I've recreated the Microsoft.Extensions.FileProviders.PhysicalFileProvider and use IFileSystem instead of System.IO to mock my service.
To ensure my classes work exactly like the PhysicalFileProvider I also copied the tests. One of the tests fails using the MockFileSystem, but not using the real FileSystem.

Test: UsePollingFileWatcher_UseActivePolling_HasChanged_SymbolicLink_TargetChanged for linkWasBroken is true.

The test with linkWasBroken is false only succeed because it reads file1Path instead of file2Path and file1Path is created, so it's a false positive.

This happens because in the (Custom|Physical)PollingFileChangeToken the (I)FileInfo is cached and only refreshed using the method Refresh().

Afaik this happens because the mocked FileInfo is detached from the storage and thus not updated.

Actual Behavior: detached FileInfo is not updated

Expected Behavior: detached FileInfo is reattached and updated

Possible Solution: Inside IFileInfo.Refresh() check the file system if the file is there and copy the infos

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions