Skip to content

[API Implementation]: SafeFileHandle overloads for SetCreationTime, SetLastAccessTime, SetLastWriteTime - #60507

Merged
jozkee merged 142 commits into
dotnet:mainfrom
deeprobin:issue-20234
Jul 12, 2022
Merged

[API Implementation]: SafeFileHandle overloads for SetCreationTime, SetLastAccessTime, SetLastWriteTime#60507
jozkee merged 142 commits into
dotnet:mainfrom
deeprobin:issue-20234

Conversation

@deeprobin

@deeprobindeeprobin commented Oct 16, 2021

Copy link
Copy Markdown
Contributor

Proposal implementation of #20234 (closes#20234)

Proposal

namespaceSystem.IO{publicstaticpartialclassFile{publicstaticDateTimeGetCreationTime(SafeFileHandlefileHandle);publicstaticDateTimeGetCreationTimeUtc(SafeFileHandlefileHandle);publicstaticDateTimeGetLastAccessTime(SafeFileHandlefileHandle);publicstaticDateTimeGetLastAccessTimeUtc(SafeFileHandlefileHandle);publicstaticDateTimeGetLastWriteTime(SafeFileHandlefileHandle);publicstaticDateTimeGetLastWriteTimeUtc(SafeFileHandlefileHandle);publicstaticvoidSetCreationTime(SafeFileHandlefileHandle,DateTimecreationTime);publicstaticvoidSetCreationTimeUtc(SafeFileHandlefileHandle,DateTimecreatinTimeUtc);publicstaticvoidSetLastAccessTime(SafeFileHandlefileHandle,DateTimelastAccessTime);publicstaticvoidSetLastAccessTimeUtc(SafeFileHandlefileHandle,DateTimelastAccessTimeUtc);publicstaticvoidSetLastWriteTime(SafeFileHandlefileHandle,DateTimelastWriteTime);publicstaticvoidSetLastWriteTimeUtc(SafeFileHandlefileHandle,DateTimelastWriteTimeUtc);publicstaticFileAttributesGetAttributes(SafeFileHandlefileHandle);publicstaticvoidSetAttributes(SafeFileHandlefileHandle,FileAttributesfileAttributes);}}

Current state of implementation

  • Proposal logic / implementation
    • Windows
    • Unix
  • Ref Assembly
  • Tests

/cc @Liryna

@ghostghost added community-contribution Indicates that the PR has been added by a community member area-System.IO labels Oct 16, 2021
@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Proposal implementation of #20234

⚠️ This is a draft

/cc @Liryna

Author:deeprobin
Assignees:-
Labels:

area-System.IO, community-contribution

Milestone:-

Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs Outdated
Comment threadsrc/libraries/Common/src/System/IO/FileSystem.Attributes.Windows.cs Outdated
@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@danmoseley Do the files added under Common/src/Interop/Windows/Kernel32/ (see CI failures) have to be registered somewhere so that they can be resolved?

@danmoseley

Copy link
Copy Markdown
Contributor

@deeprobin if you look at the build log you should see the project file on the end of the error:

2021-10-22T19:42:24.8792107Z D:\a\_work\2\s\src\libraries\Common\src\Interop\Windows\Kernel32\Interop.WIN32_FILE_ATTRIBUTE_DATA.cs(27,44): error CS0246: The type or namespace name 'BY_HANDLE_FILE_INFORMATION' could not be found (are you missing a using directive or an assembly reference?) [D:\a\_work\2\s\src\libraries\System.IO.FileSystem.AccessControl\src\System.IO.FileSystem.AccessControl.csproj]

You've introduced use of WIN32_FILE_ATTRIBUTE_DATA into a file in this project: the project file needs updating to include its source file.

@danmoseley

Copy link
Copy Markdown
Contributor

@deeprobin are you able to build the libraries locally successfully? An incremental build under src\libraries should be less than a minute, and ought to have thrown up these errors locally, which would be quicker for you than waiting an hour or whatever for the PR validation system.

Comment threadsrc/libraries/System.IO.FileSystem/tests/File/GetSetAttributes.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs Outdated
@danmoseley

Copy link
Copy Markdown
Contributor

Generally folks don't push changes one at a time, because it restarts PR validation, which is extensive -- 50+ configurations -- and that uses machine capacity. What I suggest is that you wait to push until you are satisfied with your changes and have done basic build and tests locally, then push everything (squashed or not as you prefer). Another option is that I mark this PR as draft, so that pushes don't kick off more validation (I think). What are your thoughts

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

Generally folks don't push changes one at a time, because it restarts PR validation, which is extensive -- 50+ configurations -- and that uses machine capacity. What I suggest is that you wait to push until you are satisfied with your changes and have done basic build and tests locally, then push everything (squashed or not as you prefer). Another option is that I mark this PR as draft, so that pushes don't kick off more validation (I think). What are your thoughts

Unfortunately, VS support doesn't currently work for me with .NET 7, so I've always validated that via CI.

@danmoseley

Copy link
Copy Markdown
Contributor

VS support doesn't currently work for me with .NET 7

You can build and run tests outside of VS. this is what I do. There is all the info you need in the workflow docs in this repo.

Comment threadsrc/libraries/System.IO.FileSystem/tests/File/GetSetAttributes.cs Outdated
@danmoseley

Copy link
Copy Markdown
Contributor

@deeprobin it looks like there's unix specific build errors. You don't need to be on a Unix box to reproduce those. Something like this at the root of the repo:
build clr.corelib -rc release -lc debug -os linux
or to build all the libraries
build clr.corelib+libs -rc release -lc debug -os linux

There should be a way to do it with dotnet build, but I have to check how.

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@danmoseley Thank you. I'll fixed it (the unix-build is now passing locally)

Comment threadsrc/libraries/Common/src/System/IO/FileSystem.Attributes.Windows.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs Outdated
@jozkeejozkee added the needs-author-action An issue or pull request that requires more info or actions from the author. label Dec 4, 2021
@ghostghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Dec 11, 2021
@danmoseley

Copy link
Copy Markdown
Contributor

It looks like you need to rebase on main as I made a concurrent change. It should be easy.

@huoyaoyuanhuoyaoyuan mentioned this pull request Dec 14, 2021
@danmoseley

Copy link
Copy Markdown
Contributor

Can you please open a new issue for your failure:


Process terminated. Assertion failed.
ClientCertificates. Expected enumerable cloned value.
at System.Net.Security.SslClientAuthenticationOptionsExtensions.ShallowClone(SslClientAuthenticationOptions options) in /_/src/libraries/Common/src/System/Net/Security/SslClientAuthenticationOptionsExtensions.cs:line 41
at System.Net.Http.HttpConnectionSettings.CloneAndNormalize() in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs:line 85
at System.Net.Http.SocketsHttpHandler.SetupHandlerChain() in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs:line 486
at System.Net.Http.SocketsHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs:line 576

@danmoseley

Copy link
Copy Markdown
Contributor

Cc @wfurt

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@jozkee@danmoseley
I think this PR is ready-for-merge or do you find any possible improvements?

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@jozkee Can you give another review (or approve)?

Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs
deeprobinand others added 4 commits July 11, 2022 22:37
@deeprobin
deeprobin requested a review from jozkeeJuly 11, 2022 21:09
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs
@jozkee

Copy link
Copy Markdown
Member

@deeprobin if you are not planning on addressing the documentation feedback, could you please file an issue for it?

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@deeprobin if you are not planning on addressing the documentation feedback, could you please file an issue for it?

I'll address it. Give me one hour ;)

Co-Authored-By: David Cantú <jozkyy@gmail.com>
@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@jozkee Doc changes applied

Comment threadsrc/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated
@jozkee

Copy link
Copy Markdown
Member

CI error is #66625

@jozkee
jozkee merged commit 15cb373 into dotnet:mainJul 12, 2022
@jozkee

Copy link
Copy Markdown
Member

Thanks, @deeprobin.

@ghostghost locked as resolved and limited conversation to collaborators Aug 12, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.IOcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SetCreationTime, SetLastAccessTime, SetLastWriteTime Should not open a new stream to obtain a SafeFileHandle

9 participants

@deeprobin@danmoseley@kant2002@tmds@jkoritzinsky@jozkee@stephentoub@ViktorHofer@adamsitnik