Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make Mock{File,Directory}Info cache file attributes #791

Merged
merged 4 commits into from
Jan 9, 2022

Conversation

fgreinacher
Copy link
Contributor

This makes them behave more similar to the real file system implementation

Fixes #661

This makes them behave more similar to the real file system implementation

Fixes #661
@fgreinacher
Copy link
Contributor Author

@BrianMcBrayer Wanna have a look at this? (I warned you in advance 😀)

@BrianMcBrayer
Copy link
Contributor

Yeah! I'll take a look today!

Copy link
Contributor

@BrianMcBrayer BrianMcBrayer left a comment

Choose a reason for hiding this comment

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

Looks really good and clean.

I had one comment/question about multithreading, but I don't think it's an issue.

@fgreinacher
Copy link
Contributor Author

Looks really good and clean.

I had one comment/question about multithreading, but I don't think it's an issue.

Thanks a lot for the quick review!

@fgreinacher fgreinacher merged commit 5216e0d into main Jan 9, 2022
@fgreinacher fgreinacher deleted the fix/directory-info-exists branch January 9, 2022 20:43
@github-actions
Copy link

github-actions bot commented Jan 9, 2022

This is addressed in release v16.0.8.

@github-actions github-actions bot added the state: released Issues that are released label Jan 9, 2022
siprbaum added a commit to siprbaum/System.IO.Abstractions that referenced this pull request Mar 22, 2022
In 5216e0d ("fix: make Mock{File,Directory}Info cache file attributes
(TestableIO#791)", 2022-01-09) a cache of the MockFileData was introduced, to mimic
the behaviour that a FileInfo object will not read the data from disk
but instead also remembers its internal state, which can be updated by
calling its `Refresh` method. This internal (or cached state) is
invalidated when calling the methods `Create`, `Delete` and `MoveTo`
methods, as can be seen by the `Invalidate` calls in
https://github.com/dotnet/runtime/blob/8766a1cf1ed6c3b69cef50154139699b72fb52c5/src/libraries/System.Private.CoreLib/src/System/IO/FileInfo.cs

In the PR TestableIO#791 it was overlooked to also invalidate the cached data
in these methods. This commit fixes it by invalidating the cached data
only for `Create`, `CreateText` and `Delete`.

The two `MoveTo` variants are not changed as I could not manage to find
any behaviour which is broken without that invalidation.
Most likely reason is that the  MockFileData is updated to represent the
destination file ofter the move, so invalidating is not needed.

Fixes TestableIO#822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: released Issues that are released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discrepancy between DirectoryInfo(Base).Exists in real file system and MockFileSystem DirectoryInfoBase.Exists
2 participants