-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Invalidate FileInfo and DirectoryInfo upon create and delete #34229
Conversation
@@ -50,6 +50,12 @@ private void Init(string originalPath, string? fullPath = null, string? fileName | |||
_isNormalized = isNormalized; | |||
} | |||
|
|||
private void DeleteAndInvalidate(bool recurisve) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: recurisve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here I was thinking I could spell
@@ -235,8 +241,8 @@ public void MoveTo(string destDirName) | |||
Invalidate(); | |||
} | |||
|
|||
public override void Delete() => FileSystem.RemoveDirectory(FullPath, recursive: false); | |||
public override void Delete() => DeleteAndInvalidate(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public override void Delete() => DeleteAndInvalidate(false); | |
public override void Delete() => Delete(false); |
You do not really need a new method for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Changed
@@ -141,6 +141,7 @@ internal long LengthCore | |||
} | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra new line?
@@ -235,8 +235,12 @@ public void MoveTo(string destDirName) | |||
Invalidate(); | |||
} | |||
|
|||
public override void Delete() => FileSystem.RemoveDirectory(FullPath, recursive: false); | |||
public override void Delete() => Delete(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public override void Delete() => Delete(false); | |
public override void Delete() => Delete(recursive: false); |
info.Delete(); | ||
ValidateSetTimes(info, beforeTime, afterTime); | ||
Assert.True(info.LastAccessTimeUtc > afterTime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to use Assert.InRange. If the assert fails, we'll then get meaningful informationa about why.
Also, what about the other times? ValidateSetTimes can't be used to validate those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some debugging I actually think we should bin this test. On my local machine the invalidated date time ends up being 01/01/1601
(W10), I could change it so the time isn't in the series, or is simple different than both but I think the over-all goal of the test has been invalidated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, we deleted the file. I think we have a test somewhere that validates the time we return for a non-existent file. Ideally we'd do the same check here. Otherwise, we can just delete the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephentoub after some digging I actually think something is incorrectly happening here. https://github.com/dotnet/runtime/blob/master/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.Windows.cs#L111 the underlying OS specific filesysteminfo is checking if it's been initialized, and stepping through it's set to 0, vs -1 so I'm investigating that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redacting my statement, I still think we should delete the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't we want to validate the times behave as they would for a nonexistent file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me too, but should be assert that it isn't in the range of those two times? Or just that the file has been defaulted to the system default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably we should check for the same values as in the earlier tests in this file.
https://github.com/Jlalond/runtime/blob/f204026ab55bbeae1c62252ba67bf61fdeefda5b/src/libraries/System.IO.FileSystem/tests/Base/InfoGetSetTimes.cs#L24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should've noticed that, eek. Implemented!
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath()); | ||
string testFilePath = Path.Combine(testDir.FullName, GetTestFileName()); | ||
FileInfo info = new FileInfo(testFilePath); | ||
using(FileStream fileStream = info.Create()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using(FileStream fileStream = info.Create()) | |
using (FileStream fileStream = info.Create()) |
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath()); | ||
string testFilePath = Path.Combine(testDir.FullName, GetTestFileName()); | ||
FileInfo info = new FileInfo(testFilePath); | ||
using(FileStream fileStream = info.Create()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using(FileStream fileStream = info.Create()) | |
using (FileStream fileStream = info.Create()) |
src/libraries/System.IO.FileSystem/tests/Base/InfoGetSetTimes.cs
Outdated
Show resolved
Hide resolved
@stephentoub I think I implemented all your linting and I got all the tests working old and new, could I get a final review from you or @carlossanlop / @JeremyKuhne Thanks! |
info.Delete(); | ||
ValidateSetTimes(info, beforeTime, afterTime); | ||
Assert.NotInRange(info.LastAccessTimeUtc, beforeTime, afterTime); | ||
Assert.Equal(info.LastAccessTimeUtc, DateTime.FromFileTimeUtc(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two arguments here should be swapped; the first is expected, the second is actual.
info.Delete(); | ||
ValidateSetTimes(info, beforeTime, afterTime); | ||
Assert.NotInRange(info.LastAccessTimeUtc, beforeTime, afterTime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert can be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of small comments, otherwise LGTM. Thanks.
@jaredpar would you mind bumping this build |
@stephentoub I flipped the unit test and removed the useless Assert, so I think we're good to merge on my end |
thank you @Jlalond |
Anytime @danmosemsft! I'll pick up a new issue shortly |
@Jlalond sounds good to me - we have plenty marked up for grabs. |
This is the change discussed in #31425
@wfurt