-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[API Implementation]: SafeFileHandle overloads for SetCreationTime, SetLastAccessTime, SetLastWriteTime #60507
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
Merged
Merged
Changes from all commits
Commits
Show all changes
142 commits
Select commit
Hold shift + click to select a range
80246ea
Implement proposal
deeprobin eb56003
Undo auto-reformat
deeprobin f2b6e90
Add ref
deeprobin c1c0161
Fix Parameter Naming in FileSystem.Unix.cs
deeprobin d250908
Partial test implementation
deeprobin d711b3d
Fix typo
deeprobin 3ef0ee4
Fix parameter naming
deeprobin ea88c03
Naming fix and remove unnessecary method
deeprobin ec7d870
Add more test cases
deeprobin b656f06
Implement usage of Kernel32 Method GetFileInformationByHandle and str…
deeprobin 4299f3d
Fix Test SetLastWriteTimeTicks_SafeFileHandle
deeprobin 318167e
Disable SafeFileHandle specific-tests on other platforms than Windows
deeprobin 53f5d93
Add Common reference to project file of System.IO.AccessControl
deeprobin a928024
fix
deeprobin bf7d67f
Add preprocessor variable check
deeprobin 9dc972d
Add check for preprocessor var
deeprobin 03fa5d1
Fix CS0649
deeprobin 1ad32c2
Remove preprozessor variable checks
deeprobin f424ec2
Fix tab/spaces conflict in Interop.BY_HANDLE_FILE_INFORMATION
deeprobin 007e068
Fix misplaced StructLayoutAttribute
deeprobin 6a88e68
Fix project file identation
deeprobin 092b32a
Remove preprocessor variable checks for GetSetAttributes test
deeprobin eb27249
Use ThrowHelper instead of direct throwing
deeprobin b67d6a0
Use ThrowHelper instead of direct throwing
deeprobin a1ce489
Add null-forgiving operator to fix build-failures
deeprobin 39febf3
Fix build failures
deeprobin 25ffa08
Win32 interop improvements
deeprobin ba42e76
Specify FileAccess in File.OpenHandle calls for testing purposes
deeprobin 5824743
Implement GetLastWin32Error proposal / @Jozkee
deeprobin 01c405c
Merge branch 'main' into issue-20234
deeprobin 3484035
Fix build
deeprobin 273ce50
Usage of kernel32.dll!SetFileInformationByHandle in FileSystem.SetFil…
deeprobin af3955b
Usage of access parameter in GetSetTimes tests
deeprobin af923e1
Remove auto-generated trash
deeprobin 001f45c
Add localization string to NativeAOT Strings.resx
deeprobin 1f41f14
Unix Implementation of GetAttributes, SetAttributes, GetCreationTime,…
deeprobin bce7faa
Unix Implementation SetLastAccessTime and SetLastWriteTime
deeprobin b7d7b4a
Add error handling to FChMod call
deeprobin c48c855
Revert "Unix Implementation SetLastAccessTime and SetLastWriteTime"
deeprobin 51e462e
Unix Implementation SetLastAccessTime and SetLastWriteTime
deeprobin d1752d4
Merge branch 'main' into issue-20234
deeprobin e7b5b15
Merge remote-tracking branch 'origin/main' into issue-20234
tmds b2eec67
Move SafeHandle implementation to FileStatus.
tmds 6a3e131
`SafeFileHandle` `FileStatus` (#4)
deeprobin 8de7a3c
Revert "`SafeFileHandle` `FileStatus` (#4)" (#5)
deeprobin d5bb271
Merge branch 'main' into issue-20234
deeprobin 3e2e401
Merge branch 'safehandle_filestatus' of https://github.com/tmds/runti…
deeprobin b8b85cb
Merge branch 'tmds-safehandle_filestatus' into issue-20234
deeprobin 34d11e9
Usage of `GetHandlePath`
deeprobin 02dbad3
Usage of `CULong`
deeprobin ef86395
Usage of `CULong`
deeprobin dcfd29a
Add SystemNative_FChflags
tmds 3e08682
Fix `OpenHandle` calls in test
deeprobin 1a65bf0
Add symlink resolving in `TimeFunctions` tests
deeprobin 485d516
Use `futimes` fallback for `futimens`
deeprobin 797c8f0
Use right preprocessor var
deeprobin 72c2156
Add new line at EOF in `Interop.BY_HANDLE_FILE_INFORMATION`
deeprobin 7a31c6c
Remove `FileOptions.DeleteOnClose` in Test cases for post-disposal tests
deeprobin 68e4bde
Add non linux condition to `SetDateTimeMax_SafeFileHandle` test
deeprobin 12823fe
Exclude pagefile.sys tests for `SafeFileHandle`
deeprobin 31e374e
Fix `BaseGetSetTimes` tests
deeprobin 384d8af
Use `GeneratedDllImport` over `DllImport`
deeprobin 4984e30
Remove redundant charset spec. from `Interop.UTimensat`
deeprobin 708b8b0
Remove extra line
deeprobin 6510050
Add explicit parameter names
deeprobin 3a336b7
Add explanatory comment to `TimeFunctions`
deeprobin 38e27bf
Improve test cases
deeprobin 1ca813c
Remove more redundant charset specifications
deeprobin 1ab9f08
Merge branch 'main' into issue-20234
deeprobin 84c19d8
Refactoring Tests
deeprobin e81aa89
Merge branch 'main' into issue-20234
deeprobin 136b78f
Refactor Tests
deeprobin f4bab25
Fix tests
deeprobin d32db10
Improve test structure
deeprobin b97d6e7
Merge branch 'main' into issue-20234
deeprobin 6c27da1
Remove `ExactSpelling`
deeprobin 9da4cba
Merge branch 'main' into issue-20234
deeprobin 4ad6973
Rename `GeneratedDllImportAttribute` to `LibraryImportAttribute`
deeprobin 1e85d14
Apply suggestions
deeprobin 985347e
Reduce code duplication in `FileSystem.Windows.cs`
deeprobin 214a00f
Fix tests
deeprobin bae3af1
Address feedback
deeprobin dc9ecb5
Address more feedback
deeprobin 99d6dd9
Merge branch 'main' into issue-20234
deeprobin 1d177a4
Apply suggestions & try to avoid reordering
deeprobin fc06d5b
Merge branch 'main' into issue-20234
deeprobin 1bdec8f
Fix tests
deeprobin 5b7691f
Fix tests
deeprobin 56bdc14
Refactor `BaseGetSetTimes`
deeprobin d43e8c2
Merge branch 'main' into issue-20234
deeprobin 64641ce
Merge branch 'main' into issue-20234
deeprobin 9362956
Test style changes
deeprobin f9687ac
Don't try to verify link properties don't change when we can't retrie…
tmds 695070e
Apply suggestions
deeprobin 9fe781b
Regenerate reference source
deeprobin b56a5ff
Merge branch 'main' into issue-20234
deeprobin d763b4d
Merge branch 'main' into issue-20234
deeprobin 78bf14a
Apply suggestions
deeprobin 0e8e25d
Reorder project items
deeprobin 12a6e8a
Apply suggestions
deeprobin 95114b3
Apply suggestions
deeprobin 1f3886e
Apply suggestions
deeprobin b9a310b
Merge branch 'main' into issue-20234
deeprobin 9886bbb
Fix `fsetattrlist`
deeprobin 2388c49
Apply suggestions
deeprobin 34e4c24
Fix error path resolution
deeprobin 2b5d54a
Merge branch 'main' into issue-20234
deeprobin 175d0a4
Merge branch 'main' into issue-20234
deeprobin 053842b
(Try to) fix OSX failures
deeprobin db1ff57
Fix OSX method signature
deeprobin fdd0b9c
Apply suggestions
deeprobin 1700cdd
Apply suggestions (using GitHub UI)
deeprobin 83e7017
Apply suggestions (using GitHub UI)
deeprobin 377b3ad
Merge branch 'main' into issue-20234
deeprobin 6542494
FileStatus: avoid ToString allocation for setattrlist
tmds 92b75e3
Remove unnecessary message
deeprobin 4fc1b4f
Apply suggestions
deeprobin 4fd5f7b
Merge branch 'main' into issue-20234
deeprobin 67aab4e
Fix corruption due merge
deeprobin b0d5a73
Apply suggestions
deeprobin 1fe2043
Fix Unix tests
deeprobin 168626d
Merge branch 'main' into issue-20234
deeprobin afe8cfe
Merge branch 'main' into issue-20234
deeprobin 5b59c8f
Fix tests
deeprobin 88efa3b
Update src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.…
deeprobin af9b7e7
Merge remote-tracking branch 'origin/main' into issue-20234
tmds edf948e
Fix Unix test failures.
tmds 5776aad
Sfh fix tests (#8)
deeprobin 3cc1261
Revert "Sfh fix tests (#8)" (#9)
deeprobin 4378d0b
Merge pull request #10 from tmds/sfh_fix_tests
deeprobin 3e8b4ba
Apply interop suggestions
deeprobin a9321a8
Verify non-nullability either of handle or path
deeprobin 2dbd741
Small syntax fix
deeprobin 3a1dc2e
Merge branch 'main' into issue-20234
deeprobin f0697b5
Merge branch 'main' into issue-20234
deeprobin 231c838
Add null-validation
deeprobin c63501b
Move population into private helper method
deeprobin f865a87
Fix null-handling
deeprobin 880011b
Add more debug assertions
deeprobin 312b199
Add code documentation
deeprobin 0d405b4
Address documentation feedback
deeprobin 7cfc7e1
Update src/libraries/System.Private.CoreLib/src/System/IO/File.cs
jozkee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
25 changes: 25 additions & 0 deletions
25
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.BY_HANDLE_FILE_INFORMATION.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Kernel32 | ||
| { | ||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct BY_HANDLE_FILE_INFORMATION | ||
| { | ||
| internal uint dwFileAttributes; | ||
| internal FILE_TIME ftCreationTime; | ||
| internal FILE_TIME ftLastAccessTime; | ||
| internal FILE_TIME ftLastWriteTime; | ||
| internal uint dwVolumeSerialNumber; | ||
| internal uint nFileSizeHigh; | ||
| internal uint nFileSizeLow; | ||
| internal uint nNumberOfLinks; | ||
| internal uint nFileIndexHigh; | ||
| internal uint nFileIndexLow; | ||
| } | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFileInformationByHandle.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Win32.SafeHandles; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Kernel32 | ||
| { | ||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static unsafe partial bool GetFileInformationByHandle(SafeFileHandle hFile, out BY_HANDLE_FILE_INFORMATION lpFileInformation); | ||
| } | ||
| } |
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
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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
src/libraries/System.IO.FileSystem/tests/File/GetSetAttributes_SafeFileHandle.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Win32.SafeHandles; | ||
| using Xunit; | ||
|
|
||
| namespace System.IO.Tests | ||
| { | ||
| public class GetSetAttributes_SafeFileHandle : FileGetSetAttributes | ||
| { | ||
| protected virtual SafeFileHandle OpenFileHandle(string path, FileAccess fileAccess) => | ||
| File.OpenHandle( | ||
| path, | ||
| FileMode.OpenOrCreate, | ||
| fileAccess, | ||
| FileShare.None); | ||
|
|
||
| protected override bool CanBeReadOnly => false; | ||
|
|
||
| protected override FileAttributes GetAttributes(string path) | ||
| { | ||
| using SafeFileHandle fileHandle = OpenFileHandle(path, FileAccess.Read); | ||
| return File.GetAttributes(fileHandle); | ||
| } | ||
|
|
||
| protected override void SetAttributes(string path, FileAttributes attributes) | ||
| { | ||
| using SafeFileHandle fileHandle = OpenFileHandle(path, FileAccess.ReadWrite); | ||
| File.SetAttributes(fileHandle, attributes); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void NullArgumentValidation() | ||
| { | ||
| Assert.Throws<ArgumentNullException>("fileHandle", static () => File.GetAttributes(default(SafeFileHandle)!)); | ||
| Assert.Throws<ArgumentNullException>("fileHandle", static () => File.SetAttributes(default(SafeFileHandle)!, (FileAttributes)0)); | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.