Repository navigation
Conversation
AddDirectory checked each parent with a trailing separator, but entries are stored without one, so every existing parent was replaced by a new MockDirectoryData. Creating a subdirectory therefore reset the parent's times and attributes.
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #839.
Problem
Creating a directory resets the existing parent directories. Their creation, last access and last write times go back to the current time, and their attributes are lost:
AddDirectorychecks each parent withDirectoryExistsWithoutFixingPath(segment), wheresegmentends with a separator (c:\foo\bar\). Entries are stored without one (SetEntrytrims it), so the check never finds an existing parent and every parent is replaced by a newMockDirectoryData. The same happens whenAddFilecreates the parent directories of a new file.Change
Trim the separator before the existence check. Drive roots are kept as they are by
TrimSlashes.Tests
Two tests in
MockDirectoryTests: times and attributes of an existing parent are kept after creating a subdirectory. Both fail without the change. The full solution passes on Windows (net472, net8.0, net9.0, net10.0, net11.0).Note on #839
The repro in the issue (set
LastWriteTimeon aDirectoryInfo, read it fromEnumerateDirectories) already passes onmain. I compared the mock with NTFS while looking at it: creating or deleting an entry updates the parent's last write and last access time on NTFS, and the mock never does that for directories, which is the directory side of what #875 did for files. If you want that too, I can do it in a separate PR; it is OS-specific for last access time, as discussed in the issue.