Skip to content

PhysicalFileProvider.GetFileInfo does not return info for directories, even though return type has an IsDirectory property #757

@olivier-spinelli

Description

@olivier-spinelli

A directory exists but when calling GetFileInfo to obtain an "abstract" IFIleInfo it does not.
However when a directory is returned by the enumeration of a IDirectoryContents, a IFileInfo is correctly returned (with both Exists and IsDirectory sets to true).

This means that the code that handles a IFileInfo HAS to be aware of how it has been created/obtained.

[Test]
public void standard_physical_file_provider_is_full_of_surprises()
{
   using( var pStd = new PhysicalFileProvider( LocalTestHelper.WorldFolder ) )
   {
       var fCA = pStd.GetDirectoryContents( "TestGitRepository" );
       fCA.Exists.Should().BeTrue( "Yes, this is a directory..." );

        var fA = pStd.GetFileInfo( "TestGitRepository" );

        fA.IsDirectory.Should().BeFalse( "What??? This IS a directory!" );
        fA.Exists.Should().BeFalse( "And it DOES exist !" );
   }
}

I suspect that this oddity is due to the FileSystemInfo being abstract: the current code uses a new FileInfo for its PhysicalFileInfo returned object, totally missing the IsDirectory possibility.

Any chance for this to be fixed? Or should I go with my own SimplePhysicalFileProvider?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions