Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
10379ce
Fix setting creation date for OSX
hamarb123 Mar 12, 2021
2ade343
Fix setting creation date for OSX - fix for setattrlist
hamarb123 Mar 16, 2021
aea57ed
Fix setting creation date for OSX - fix for caching when set time & p…
hamarb123 Mar 17, 2021
be1774c
Fix setting creation date for OSX - changes for PR 1
hamarb123 Mar 18, 2021
e39f5a2
Fix setting creation date for OSX - changes for PR 2
hamarb123 Mar 18, 2021
69f7c09
Fix setting creation date for OSX - changes for PR 3
hamarb123 Mar 20, 2021
edaf35e
Fix setting creation date for OSX - fix test for Windows and browser …
hamarb123 Mar 21, 2021
4abaa29
Fix setting creation date for OSX - make modification time use normal…
hamarb123 Mar 21, 2021
b85f323
Fix setting creation date for OSX - hotfix: Remove ATTR_CMN_MODTIME
hamarb123 Mar 21, 2021
a617a01
Fix setting creation date for OSX - revert windows changes & simplify…
hamarb123 Mar 23, 2021
f84f10e
Fix setting creation date for OSX - hotfix: change to CULong for mars…
hamarb123 Mar 23, 2021
9ce96e5
Fix setting creation date for OSX - hotfix: change to CULong for mars…
hamarb123 Mar 23, 2021
54a6266
Fix setting creation date for OSX - consolidate unix nanosecond calcu…
hamarb123 Mar 24, 2021
c80ef95
Merge branch 'main' into main
hamarb123 May 9, 2021
50945f8
Use InvalidateCaches instead of Invalidate and EnsureCachesInitialize…
hamarb123 May 9, 2021
f325717
Fixes for reviews in PR #49555
hamarb123 May 17, 2021
19cbb7f
Hotfix for missing parameter
hamarb123 May 17, 2021
2b702e3
Fix naming
hamarb123 May 17, 2021
f1a303e
Revert changes re SettingUpdatesPropertiesAfterAnother (mainly) and r…
hamarb123 May 18, 2021
0bbfbed
Fix errors of #49555 due to missing variables
hamarb123 May 25, 2021
42ca7e1
Remove the parameters that were meant to be removed
hamarb123 May 25, 2021
b15ceeb
Merge remote-tracking branch 'upstream/main'
hamarb123 May 29, 2021
7440772
Finish merge
hamarb123 May 29, 2021
e550082
Remove duplicate file
hamarb123 May 30, 2021
17868b1
Add custom error handling for setattrlist
hamarb123 May 30, 2021
f842935
Remove symlink specific code from this PR
hamarb123 Sep 7, 2021
1ca19ff
Remove custom ENOTDIR handling, enable tests for other OSX-like platf…
hamarb123 Sep 9, 2021
347f750
Rename files according to review
hamarb123 Sep 9, 2021
9928e3e
Change names of functions to improve readability and refactor code
hamarb123 Sep 10, 2021
15e9fc9
Fix the wrongly named variable and add the missing 'unsafe' keyword
hamarb123 Sep 10, 2021
5d20106
Merge branch 'dotnet:main' into main
hamarb123 Sep 11, 2021
581a669
Better comments and minor improvements
hamarb123 Sep 15, 2021
0623c42
Add additional tests and improvements
hamarb123 Oct 9, 2021
1ac43cc
Fix typos
hamarb123 Oct 9, 2021
11b26d8
Merge remote-tracking branch 'upstream/main'
hamarb123 Oct 9, 2021
8190220
Revert to <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreApp…
hamarb123 Oct 11, 2021
8aa9685
Remove SettingOneTimeMaintainsOtherDefaultTimes and AllDefaultTimesAr…
hamarb123 Oct 11, 2021
d8ec4fb
Fix: setattrlist can only return 0 or -1
hamarb123 Oct 19, 2021
6931bd0
Merge remote-tracking branch 'upstream/main'
hamarb123 Oct 19, 2021
57a1229
Update code comment for SettingUpdatesPropertiesAfterAnother test
hamarb123 Oct 19, 2021
9c6ab2b
Update code comment for SettingUpdatesPropertiesAfterAnother test
hamarb123 Oct 19, 2021
1fdc325
Update comment for SettingUpdatesPropertiesAfterAnother for consistency
hamarb123 Oct 19, 2021
6aa1852
Fixes for compilation and update to comment
hamarb123 Oct 19, 2021
31db20b
Update FileStatus.SetTimes.OSX.cs
hamarb123 Oct 19, 2021
c7c11d2
Move comments and add explicit types to SettingUpdatesPropertiesAfter…
hamarb123 Oct 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ internal static partial class Libraries
internal const string SystemConfigurationLibrary = "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration";
internal const string AppleCryptoNative = "libSystem.Security.Cryptography.Native.Apple";
internal const string MsQuic = "libmsquic.dylib";
internal const string libc = "libc";
}
}
32 changes: 32 additions & 0 deletions src/libraries/Common/src/Interop/OSX/Interop.libc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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
{
[StructLayout(LayoutKind.Sequential)]
internal struct AttrList
{
[MarshalAs(UnmanagedType.U2)] public ushort bitmapCount;
[MarshalAs(UnmanagedType.U2)] public ushort reserved;
[MarshalAs(UnmanagedType.U4)] public uint commonAttr;
[MarshalAs(UnmanagedType.U4)] public uint volAttr;
[MarshalAs(UnmanagedType.U4)] public uint dirAttr;
[MarshalAs(UnmanagedType.U4)] public uint fileAttr;
[MarshalAs(UnmanagedType.U4)] public uint forkAttr;

public const ushort ATTR_BIT_MAP_COUNT = 5;
public const uint ATTR_CMN_CRTIME = 0x00000200;
public const uint ATTR_CMN_MODTIME = 0x00000400;
}

[DllImport(Libraries.libc, EntryPoint = "setattrlist", SetLastError = true)]
internal static unsafe extern int setattrlist(string path, AttrList* attrList, void* attrBuf, nint attrBufSize, uint options);

internal const uint FSOPT_NOFOLLOW = 0x00000001;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsBrowser)' == 'true'">
Expand Down Expand Up @@ -231,6 +231,16 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetEGid.cs"
Link="Common\Interop\Unix\Interop.GetEGid.cs" />
</ItemGroup>
<ItemGroup Condition="('$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true') and '$(TargetsOSX)' != 'true'">
<Compile Include="System\IO\FileStatus.OtherUnix.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsOSX)' == 'true'">
<Compile Include="$(CommonPath)Interop\OSX\Interop.Libraries.cs"
Link="Common\Interop\OSX\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\OSX\Interop.libc.cs"
Link="Common\Interop\OSX\Interop.libc.cs" />
<Compile Include="System\IO\FileStatus.OSX.cs" />
</ItemGroup>
<!-- Unix references -->
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true'">
<Reference Include="System.Threading" />
Expand Down
55 changes: 55 additions & 0 deletions src/libraries/System.IO.FileSystem/src/System/IO/FileStatus.OSX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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) => SetTimeOnFile(path, time, Interop.libc.AttrList.ATTR_CMN_CRTIME);
internal void SetLastWriteTime(string path, DateTimeOffset time) => SetTimeOnFile(path, time, Interop.libc.AttrList.ATTR_CMN_MODTIME);

private unsafe void SetTimeOnFile(string path, DateTimeOffset time, uint commonAttr)
{
Interop.Sys.TimeSpec timeSpec = default;

long seconds = time.ToUnixTimeSeconds();

const long TicksPerMillisecond = 10000;
const long TicksPerSecond = TicksPerMillisecond * 1000;
long nanoseconds = (time.UtcDateTime.Ticks - DateTimeOffset.UnixEpoch.Ticks - seconds * TicksPerSecond) * NanosecondsPerTick;

timeSpec.TvSec = seconds;
timeSpec.TvNsec = nanoseconds;

Interop.libc.AttrList attrList = default;
attrList.bitmapCount = Interop.libc.AttrList.ATTR_BIT_MAP_COUNT;
attrList.reserved = 0;
attrList.commonAttr = commonAttr;
attrList.dirAttr = 0;
attrList.fileAttr = 0;
attrList.forkAttr = 0;
attrList.volAttr = 0;

// Try to set the attribute on the file system entry using setattrlist,
// otherwise fall back to the method used on other unix platforms as the
// path may either be on an unsupported volume type (for setattrlist) or it
// could be another error (eg. no file) which the fallback implementation can throw.
bool succeeded = Interop.libc.setattrlist(path, &attrList, &timeSpec, sizeof(Interop.Sys.TimeSpec), Interop.libc.FSOPT_NOFOLLOW) == 0;
if (!succeeded)
{
if (commonAttr == Interop.libc.AttrList.ATTR_CMN_CRTIME)
{
SetCreationTime_OtherUnix(path, time);
}
else if (commonAttr == Interop.libc.AttrList.ATTR_CMN_MODTIME)
{
SetLastWriteTime_OtherUnix(path, time);
}
}

_fileStatusInitialized = -1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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) => SetCreationTime_OtherUnix(path, time);
internal void SetLastWriteTime(string path, DateTimeOffset time) => SetLastWriteTime_OtherUnix(path, time);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace System.IO
{
internal struct FileStatus
internal partial struct FileStatus
{
private const int NanosecondsPerTick = 100;

Expand Down Expand Up @@ -186,7 +186,7 @@ internal DateTimeOffset GetCreationTime(ReadOnlySpan<char> path, bool continueOn
return UnixTimeToDateTimeOffset(_fileStatus.CTime, _fileStatus.CTimeNsec);
}

internal void SetCreationTime(string path, DateTimeOffset time)
private void SetCreationTime_OtherUnix(string path, DateTimeOffset time)
{
// Unix provides APIs to update the last access time (atime) and last modification time (mtime).
// There is no API to update the CreationTime.
Expand All @@ -197,7 +197,7 @@ internal void SetCreationTime(string path, DateTimeOffset time)
// Updating the mtime, causes the ctime to be set to 'now'. So, on platforms that don't store a
// CreationTime, GetCreationTime will return the value that was previously set (when that value
// wasn't in the future).
SetLastWriteTime(path, time);
SetLastWriteTime_OtherUnix(path, time);
}

internal DateTimeOffset GetLastAccessTime(ReadOnlySpan<char> path, bool continueOnError = false)
Expand All @@ -218,7 +218,7 @@ internal DateTimeOffset GetLastWriteTime(ReadOnlySpan<char> path, bool continueO
return UnixTimeToDateTimeOffset(_fileStatus.MTime, _fileStatus.MTimeNsec);
}

internal void SetLastWriteTime(string path, DateTimeOffset time) => SetAccessOrWriteTime(path, time, isAccessTime: false);
private void SetLastWriteTime_OtherUnix(string path, DateTimeOffset time) => SetAccessOrWriteTime(path, time, isAccessTime: false);

private DateTimeOffset UnixTimeToDateTimeOffset(long seconds, long nanoseconds)
{
Expand All @@ -227,6 +227,8 @@ private DateTimeOffset UnixTimeToDateTimeOffset(long seconds, long nanoseconds)

private unsafe void SetAccessOrWriteTime(string path, DateTimeOffset time, bool isAccessTime)
{
//only used for access time on OSX (unless being used as a fallback), used for both on other unix platforms

// force a refresh so that we have an up-to-date times for values not being overwritten
_fileStatusInitialized = -1;
EnsureStatInitialized(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

internal static class IOInputs
{
public static bool SupportsSettingCreationTime => OperatingSystem.IsWindows();
public static bool SupportsSettingCreationTime => OperatingSystem.IsWindows() || OperatingSystem.IsMacOS();
public static bool SupportsGettingCreationTime => OperatingSystem.IsWindows() || OperatingSystem.IsMacOS();

// Max path length (minus trailing \0). Unix values vary system to system; just using really long values here likely to be more than on the average system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>

<RunTestsJSArguments>--working-dir=/test-dir</RunTestsJSArguments>
</PropertyGroup>
Expand Down