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

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

Conversation

vbreuss
Copy link
Member

@vbreuss vbreuss commented Aug 10, 2022

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.

var fixedTime = new DateTime(2022, 01, 01);
var fileSystem = new MockFileSystem().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

@vbreuss vbreuss changed the title feat: Set Creation, LastAccess and LastWrite time for files feat: #872 Set Creation, LastAccess and LastWrite time for files Aug 10, 2022
@vbreuss vbreuss force-pushed the feature/872-set-creation-last-access-and-last-write-times branch 3 times, most recently from 7ecbd63 to 30df259 Compare August 11, 2022 18:52
@vbreuss
Copy link
Member Author

vbreuss commented Aug 11, 2022

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

@vbreuss vbreuss changed the title feat: #872 Set Creation, LastAccess and LastWrite time for files feat: Set Creation, LastAccess and LastWrite time for files Aug 16, 2022
@vbreuss
Copy link
Member Author

vbreuss commented Aug 17, 2022

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
Contributor

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

Copy link
Contributor

@fgreinacher fgreinacher left a comment

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!

vbtig and 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 vbreuss force-pushed the feature/872-set-creation-last-access-and-last-write-times branch from 510c290 to 99ebdab Compare August 26, 2022 10:21
@vbreuss vbreuss requested a review from siprbaum August 26, 2022 10:25
@vbreuss
Copy link
Member Author

vbreuss commented Aug 31, 2022

@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?

@vbreuss
Copy link
Member Author

vbreuss commented Sep 2, 2022

@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?

@vbreuss
Copy link
Member Author

vbreuss commented Sep 10, 2022

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

vbreuss and 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>
@fgreinacher fgreinacher changed the title feat: Set Creation, LastAccess and LastWrite time for files feat: set Creation, LastAccess and LastWrite time for files Sep 16, 2022
@github-actions
Copy link

This is addressed in release v17.2.3.

@github-actions github-actions bot added the state: released Issues that are released label Nov 18, 2022
@github-actions
Copy link

This is addressed in release v17.2.3.

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.

5 participants