Skip to content

[FileSystem] Bug: Using IFile.Write... does not update IFileInfo.LastWriteTimeUtc #817

@pw-sgr

Description

@pw-sgr

As the title states using the different write methods of IFile does not change the LastWriteTimeUtc of IFileInfo. Refresh() is called.

In the following example both Console.WriteLine write the same time

Code:

        public static async Task Main(string[] args)
        {
            var fileSystem = new MockFileSystem();
            IFileInfo fileInfo = fileSystem.FileInfo.New("test.txt");
            fileInfo.Create().Dispose();
            fileInfo.Refresh();
            Console.WriteLine(fileInfo.LastWriteTimeUtc);
            await Task.Delay(2000);
            fileSystem.File.WriteAllText(fileInfo.FullName, "test");
            fileInfo.Refresh();
            Console.WriteLine(fileInfo.LastWriteTimeUtc);
        }

Actual Behavior: IFileInfo.LastWriteTimeUtc is not updated after using IFile.Write...

Expected Behavior: IFileInfo.LastWriteTimeUtc is updated to be 2s after the previous read

Possible Solution: It could be related to [FileSystem] Bug: Caching IFileInfo, recreating it, will result in stale cache

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