-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix setting creation date for OSX-like platforms #49555
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 39 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
10379ce
Fix setting creation date for OSX
hamarb123 2ade343
Fix setting creation date for OSX - fix for setattrlist
hamarb123 aea57ed
Fix setting creation date for OSX - fix for caching when set time & p…
hamarb123 be1774c
Fix setting creation date for OSX - changes for PR 1
hamarb123 e39f5a2
Fix setting creation date for OSX - changes for PR 2
hamarb123 69f7c09
Fix setting creation date for OSX - changes for PR 3
hamarb123 edaf35e
Fix setting creation date for OSX - fix test for Windows and browser …
hamarb123 4abaa29
Fix setting creation date for OSX - make modification time use normal…
hamarb123 b85f323
Fix setting creation date for OSX - hotfix: Remove ATTR_CMN_MODTIME
hamarb123 a617a01
Fix setting creation date for OSX - revert windows changes & simplify…
hamarb123 f84f10e
Fix setting creation date for OSX - hotfix: change to CULong for mars…
hamarb123 9ce96e5
Fix setting creation date for OSX - hotfix: change to CULong for mars…
hamarb123 54a6266
Fix setting creation date for OSX - consolidate unix nanosecond calcu…
hamarb123 c80ef95
Merge branch 'main' into main
hamarb123 50945f8
Use InvalidateCaches instead of Invalidate and EnsureCachesInitialize…
hamarb123 f325717
Fixes for reviews in PR #49555
hamarb123 19cbb7f
Hotfix for missing parameter
hamarb123 2b702e3
Fix naming
hamarb123 f1a303e
Revert changes re SettingUpdatesPropertiesAfterAnother (mainly) and r…
hamarb123 0bbfbed
Fix errors of #49555 due to missing variables
hamarb123 42ca7e1
Remove the parameters that were meant to be removed
hamarb123 b15ceeb
Merge remote-tracking branch 'upstream/main'
hamarb123 7440772
Finish merge
hamarb123 e550082
Remove duplicate file
hamarb123 17868b1
Add custom error handling for setattrlist
hamarb123 f842935
Remove symlink specific code from this PR
hamarb123 1ca19ff
Remove custom ENOTDIR handling, enable tests for other OSX-like platf…
hamarb123 347f750
Rename files according to review
hamarb123 9928e3e
Change names of functions to improve readability and refactor code
hamarb123 15e9fc9
Fix the wrongly named variable and add the missing 'unsafe' keyword
hamarb123 5d20106
Merge branch 'dotnet:main' into main
hamarb123 581a669
Better comments and minor improvements
hamarb123 0623c42
Add additional tests and improvements
hamarb123 1ac43cc
Fix typos
hamarb123 11b26d8
Merge remote-tracking branch 'upstream/main'
hamarb123 8190220
Revert to <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreApp…
hamarb123 8aa9685
Remove SettingOneTimeMaintainsOtherDefaultTimes and AllDefaultTimesAr…
hamarb123 d8ec4fb
Fix: setattrlist can only return 0 or -1
hamarb123 6931bd0
Merge remote-tracking branch 'upstream/main'
hamarb123 57a1229
Update code comment for SettingUpdatesPropertiesAfterAnother test
hamarb123 9c6ab2b
Update code comment for SettingUpdatesPropertiesAfterAnother test
hamarb123 1fdc325
Update comment for SettingUpdatesPropertiesAfterAnother for consistency
hamarb123 6aa1852
Fixes for compilation and update to comment
hamarb123 31db20b
Update FileStatus.SetTimes.OSX.cs
hamarb123 c7c11d2
Move comments and add explicit types to SettingUpdatesPropertiesAfter…
hamarb123 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class libc | ||
carlossanlop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct AttrList | ||
| { | ||
| public ushort bitmapCount; | ||
| public ushort reserved; | ||
| public uint commonAttr; | ||
| public uint volAttr; | ||
| public uint dirAttr; | ||
| public uint fileAttr; | ||
| public uint forkAttr; | ||
|
|
||
| public const ushort ATTR_BIT_MAP_COUNT = 5; | ||
| public const uint ATTR_CMN_CRTIME = 0x00000200; | ||
| } | ||
|
|
||
| [DllImport(Libraries.libc, EntryPoint = "setattrlist", SetLastError = true)] | ||
hamarb123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| internal static unsafe extern int setattrlist(string path, AttrList* attrList, void* attrBuf, nint attrBufSize, CULong options); | ||
| } | ||
| } | ||
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
60 changes: 60 additions & 0 deletions
60
src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.SetTimes.OSX.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,60 @@ | ||
| // 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; | ||
|
|
||
| namespace System.IO | ||
| { | ||
| internal partial struct FileStatus | ||
| { | ||
| internal void SetCreationTime(string path, DateTimeOffset time) | ||
| { | ||
| // Try to set the attribute on the file system entry using setattrlist, | ||
| // if we get ENOTSUP then it means that "The volume does not support | ||
| // setattrlist()", so we fall back to the method used on other unix | ||
| // platforms, otherwise we throw an error if we get one, or invalidate | ||
| // the cache if successful because otherwise it has invalid information. | ||
| // Note: the unix fallback implementation doesn't have a test as we are | ||
| // yet to determine which volume types it can fail on, so modify with | ||
| // great care. | ||
| long seconds = time.ToUnixTimeSeconds(); | ||
| long nanoseconds = UnixTimeSecondsToNanoseconds(time, seconds); | ||
| Interop.Error error = SetCreationTimeCore(path, seconds, nanoseconds); | ||
|
|
||
| if (error == Interop.Error.SUCCESS) | ||
| { | ||
| InvalidateCaches(); | ||
| } | ||
| else if (error == Interop.Error.ENOTSUP) | ||
| { | ||
| SetAccessOrWriteTimeCore(path, time, isAccessTime: false, checkCreationTime: false); | ||
| } | ||
| else | ||
| { | ||
| Interop.CheckIo(error, path, InitiallyDirectory); | ||
| } | ||
| } | ||
|
|
||
| private unsafe Interop.Error SetCreationTimeCore(string path, long seconds, long nanoseconds) | ||
| { | ||
| Interop.Sys.TimeSpec timeSpec = default; | ||
|
|
||
| timeSpec.TvSec = seconds; | ||
| timeSpec.TvNsec = nanoseconds; | ||
|
|
||
| Interop.libc.AttrList attrList = default; | ||
| attrList.bitmapCount = Interop.libc.AttrList.ATTR_BIT_MAP_COUNT; | ||
| attrList.commonAttr = Interop.libc.AttrList.ATTR_CMN_CRTIME; | ||
|
|
||
| Interop.Error error = | ||
| Interop.libc.setattrlist(path, &attrList, &timeSpec, sizeof(Interop.Sys.TimeSpec), default(CULong)) == 0 ? | ||
| Interop.Error.Success : | ||
| Interop.Sys.GetLastErrorInfo(); | ||
|
|
||
| return error; | ||
| } | ||
|
|
||
| private void SetAccessOrWriteTime(string path, DateTimeOffset time, bool isAccessTime) => | ||
| SetAccessOrWriteTimeCore(path, time, isAccessTime, checkCreationTime: true); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.SetTimes.OtherUnix.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,20 @@ | ||
| // 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; | ||
|
|
||
| namespace System.IO | ||
| { | ||
| internal partial struct FileStatus | ||
| { | ||
| internal void SetCreationTime(string path, DateTimeOffset time) => | ||
| SetLastWriteTime(path, time); | ||
|
|
||
| private void SetAccessOrWriteTime(string path, DateTimeOffset time, bool isAccessTime) => | ||
| SetAccessOrWriteTimeCore(path, time, isAccessTime, checkCreationTime: false); | ||
|
|
||
| // This is not used on these platforms, but is needed for source compat | ||
| private Interop.Error SetCreationTimeCore(string path, long seconds, long nanoseconds) => | ||
| throw new InvalidOperationException(); | ||
| } | ||
| } |
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
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.