Skip to content

feat: set Creation, LastAccess and LastWrite time for files - #875

Merged
mergify[bot] merged 16 commits into
TestableIO:mainfrom
vbreuss:feature/872-set-creation-last-access-and-last-write-times
Sep 16, 2022
Merged

feat: set Creation, LastAccess and LastWrite time for files#875
mergify[bot] merged 16 commits into
TestableIO:mainfrom
vbreuss:feature/872-set-creation-last-access-and-last-write-times

Conversation

@vbreuss

@vbreussvbreuss commented Aug 10, 2022

Copy link
Copy Markdown
Member

Implements #872
Adjust CreationTime, LastAccessTime and LastWriteTime when interacting with files in the MockFileSystem.

Provides a means to mock the used DateTime by calling e.g.

varfixedTime=newDateTime(2022,01,01);varfileSystem=newMockFileSystem().MockTime(()=>fixedTime);// All times will now be set to the fixedTime.

Implementes the following logic in MockFile:
All these cases are covered by unit tests in MockFileAdjustTimesTest

  • When creating files
    CreationTime, LastAccessTime and LastWriteTime are set to the current time
  • When changing files (WriteAllText, WriteAllBytes, AppendAllText, OpenWrite, Open)
    LastAccessTime and LastWriteTime are set to the current time
    CreationTime is left unchanged
  • When reading files (ReadAllText, ReadAllLines, ReadAllBytes, OpenRead)
    LastAccessTime is set to the current time
    CreationTime and LastWriteTime are left unchanged
  • When setting attributes or ACLs (SetAttributes, SetAccessControl)
    LastAccessTime is set to the current time
    CreationTime and LastWriteTime are left unchanged
  • When moving files (Move)
    LastAccessTime is set to the current time
    CreationTime and LastWriteTime are left unchanged
  • When copying files (Copy)
    CreationTime and LastAccessTime of the copied file in the destination directory is set to the current time
    LastWriteTime and all times of the source file are left unchanged

@vbreussvbreuss changed the title feat: Set Creation, LastAccess and LastWrite time for filesfeat: #872 Set Creation, LastAccess and LastWrite time for filesAug 10, 2022
@vbreuss
vbreussforce-pushed the feature/872-set-creation-last-access-and-last-write-times branch 3 times, most recently from 7ecbd63 to 30df259CompareAugust 11, 2022 18:52
@vbreuss

vbreuss commented Aug 11, 2022

Copy link
Copy Markdown
MemberAuthor

Please note, that I changed the Interface IMockFileDataAccessor.
This interface looks like it is intended for internal use, but as it is public this could be considered a breaking change...

I am not sure what I should do:
I could increase the version or use default interface methods from C# 8

@vbreussvbreuss changed the title feat: #872 Set Creation, LastAccess and LastWrite time for filesfeat: Set Creation, LastAccess and LastWrite time for filesAug 16, 2022
@vbreuss

Copy link
Copy Markdown
MemberAuthor

If this is an accepted approach, I could also try to have a look at #839, which deals with the times of directories. This would probably be quite similar...

@fgreinacher

Copy link
Copy Markdown
Contributor

Sorry @vbreuss, I'm a bit busy with other things, will try to have a look by the end of this week!

Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs Outdated
Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs Outdated
Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs Outdated
Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs Outdated

@fgreinacherfgreinacher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vbreuss Looks very good so far, I made some suggestions.

I'm leaving for summer vacation soon, feel free to finish the review with @siprbaum and ping me for merge!

Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs Outdated
Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs
Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs Outdated
vbtigand others added 3 commits August 26, 2022 12:14
Also apply time in MockFileStream
Mark MockFile_AfterSetAccessControl_ShouldUpdateLastAccessTime as Windows-Only
Fix name of unit tests to match the actual expected behavior
@vbreuss
vbreussforce-pushed the feature/872-set-creation-last-access-and-last-write-times branch from 510c290 to 99ebdabCompareAugust 26, 2022 10:21
@vbreuss
vbreuss requested a review from siprbaumAugust 26, 2022 10:25
@vbreuss

Copy link
Copy Markdown
MemberAuthor

@siprbaum : I merged the latest changes, so that this branch is up to date.
All comments are either fixed and resolved, or I left a comment explaining, why I implemented it this way. Could you please have a look again at this pull request?

Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFile.cs Outdated
Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileData.cs
Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileStream.cs
@vbreuss

Copy link
Copy Markdown
MemberAuthor

@siprbaum : Thanks for the review!
I implemented the changes and answered your findings.
Can you please have a look again, and resolve the comments, that you agree with?

Regarding the user detectable behaviour change:
As we are now setting the times correctly, the behaviour changes when previously in the tests you would (incorrectly) rely upon unchanged times for the files.
However I am still unsure, if I should increment the version when considering my previous comment in this pull request, regarding the change in the interface IMockFileDataAccessor.
What do you think?

Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileData.cs
@vbreuss

Copy link
Copy Markdown
MemberAuthor

@fgreinacher : I merged the latest main branch and answered or fixed all review comments.
Can you please have a look?

Comment threadsrc/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs Outdated
Comment threadsrc/System.IO.Abstractions.TestingHelpers/TimeAdjustments.cs Outdated
vbreussand others added 3 commits September 13, 2022 13:27
Co-authored-by: Florian Greinacher <florian@greinacher.de>
Co-authored-by: Florian Greinacher <florian@greinacher.de>
@fgreinacherfgreinacher changed the title feat: Set Creation, LastAccess and LastWrite time for filesfeat: set Creation, LastAccess and LastWrite time for filesSep 16, 2022
@github-actions

Copy link
Copy Markdown

This is addressed in release v17.2.3.

@github-actionsgithub-actionsBot added the state: released Issues that are released label Nov 18, 2022
@github-actions

Copy link
Copy Markdown

This is addressed in release v17.2.3.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: releasedIssues that are released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@vbreuss@fgreinacher@xtopaz@siprbaum@vbtig