Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 48 additions & 0 deletions src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#nullable enable

using System;
using System.IO;
using System.Runtime.InteropServices;

internal static partial class Interop
Expand Down Expand Up @@ -56,5 +57,52 @@ internal static Version GetOperatingSystemVersion()

[DllImport(Libraries.libobjc, EntryPoint = MessageSendStructReturnEntryPoint)]
private static extern NSOperatingSystemVersion get_operatingSystemVersion(IntPtr basePtr, IntPtr selector);

[DllImport(Libraries.libobjc)]
private static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector, double secs); //used for 'initWithTimeIntervalSince1970:'
[DllImport(Libraries.libobjc)]
private static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector, [MarshalAs(UnmanagedType.LPUTF8Str)] string nullTerminatedCString); //used for 'initWithUTF8String:'
[DllImport(Libraries.libobjc)]
private static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector, IntPtr @object, IntPtr key); //used for 'dictionaryWithObject:forKey:'
[DllImport(Libraries.libobjc)]
private static extern byte objc_msgSend(IntPtr basePtr, IntPtr selector, IntPtr attributes, IntPtr path, IntPtr error); //used for 'setAttributes:ofItemAtPath:error:'

internal static void SetCreationOrModificationTimeOfFileInternal(string path, bool isModificationDate, DateTimeOffset time)
{
var NSDate = objc_getClass("NSDate");
var NSDictionary = objc_getClass("NSDictionary");
var NSFileManager = objc_getClass("NSFileManager");
var NSString = objc_getClass("NSString");
var alloc = sel_getUid("alloc");
var initWithUTF8String_ = sel_getUid("initWithUTF8String:");
var initWithTimeIntervalSince1970_ = sel_getUid("initWithTimeIntervalSince1970:");
var dictionaryWithObject_forKey_ = sel_getUid("dictionaryWithObject:forKey:");
var defaultManager = sel_getUid("defaultManager");
var setAttributes_ofItemAtPath_error_ = sel_getUid("setAttributes:ofItemAtPath:error:");
var release = sel_getUid("release");
var NSFileCreationOrModificationDate = objc_msgSend(objc_msgSend(NSString, alloc), initWithUTF8String_, isModificationDate ? "NSFileModificationDate" : "NSFileCreationDate");
var DefaultNSFileManager = objc_msgSend(NSFileManager, defaultManager);

var date = objc_msgSend(NSDate, alloc);
date = objc_msgSend(date, initWithTimeIntervalSince1970_, (time - DateTimeOffset.UnixEpoch).TotalSeconds);
var fileAttributes = objc_msgSend(NSDictionary, dictionaryWithObject_forKey_, date, NSFileCreationOrModificationDate);
var native_filePath = objc_msgSend(NSString, alloc);
native_filePath = objc_msgSend(native_filePath, initWithUTF8String_, path);
try
{
if (objc_msgSend(DefaultNSFileManager, setAttributes_ofItemAtPath_error_, fileAttributes, native_filePath, IntPtr.Zero) != 1)
{
//throw an error of some sort - need to change
throw new IOException("Could not set the creation date of the file.");
}
}
finally
{
objc_msgSend(date, release);
objc_msgSend(fileAttributes, release);
objc_msgSend(native_filePath, release);
objc_msgSend(NSFileCreationOrModificationDate, release);
}
}
}
}
77 changes: 70 additions & 7 deletions src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>System.IO.FileSystem</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-FreeBSD</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -172,8 +172,8 @@
<Compile Include="System\IO\FileSystem.Windows.cs" />
<Compile Include="System\IO\FileSystemInfo.Windows.cs" />
</ItemGroup>
<!-- Unix files -->
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true'">
<!-- Linux, FreeBSD, Browser files -->
<ItemGroup Condition="'$(TargetsLinux)' == 'true' or '$(TargetsFreeBSD)' == 'true' or '$(TargetsBrowser)' == 'true'">
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Link="Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.IOErrors.cs"
Expand Down Expand Up @@ -222,13 +222,76 @@
Link="Common\System\Text\ValueUtf8Converter.cs" />
<Compile Include="System\IO\Enumeration\FileSystemEntry.Unix.cs" />
<Compile Include="System\IO\Enumeration\FileSystemEnumerator.Unix.cs" />
<Compile Include="System\IO\FileStatus.Unix.cs" />
<Compile Include="System\IO\FileStatus.OtherUnix.cs" />
<Compile Include="System\IO\FileSystem.Exists.Unix.cs" />
<Compile Include="System\IO\FileSystem.Unix.cs" />
<Compile Include="System\IO\FileSystemInfo.Unix.cs" />
</ItemGroup>
<!-- Unix references -->
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true'">
<!-- Linux, FreeBSD, Browser references -->
<ItemGroup Condition="'$(TargetsLinux)' == 'true' or '$(TargetsFreeBSD)' == 'true' or '$(TargetsBrowser)' == 'true'">
<Reference Include="System.Threading" />
</ItemGroup>
<!-- OSX files -->
<ItemGroup Condition="'$(TargetsOSX)' == 'true'">
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Link="Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.IOErrors.cs"
Link="Interop\Unix\Interop.IOErrors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetEUid.cs"
Link="Common\Interop\Unix\Interop.GetEUid.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.MountPoints.cs"
Link="Common\Interop\Unix\Interop.MountPoints.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Permissions.cs"
Link="Common\Interop\Unix\Interop.Permissions.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Read.cs"
Link="Common\Interop\Unix\Interop.Read.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.ReadDir.cs"
Link="Common\Interop\Unix\Interop.ReadDir.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Stat.cs"
Link="Common\Interop\Unix\Interop.Stat.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Unlink.cs"
Link="Common\Interop\Unix\Interop.Unlink.cs" />
<Compile Include="$(CoreLibSharedDir)System\IO\DriveInfoInternal.Unix.cs"
Link="Common\System\IO\DriveInfoInternal.Unix.cs" />
<Compile Include="$(CoreLibSharedDir)System\IO\PathInternal.Unix.cs"
Link="System\IO\PathInternal.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
Link="Common\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.ChMod.cs"
Link="Common\Interop\Unix\Interop.ChMod.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.CopyFile.cs"
Link="Common\Interop\Unix\Interop.CopyFile.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetEGid.cs"
Link="Common\Interop\Unix\Interop.GetEGid.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.LChflags.cs"
Link="Common\Interop\Unix\Interop.LChflags.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Link.cs"
Link="Common\Interop\Unix\Interop.Link.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.MkDir.cs"
Link="Common\Interop\Unix\Interop.MkDir.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Rename.cs"
Link="Common\Interop\Unix\Interop.Rename.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.RmDir.cs"
Link="Common\Interop\Unix\Interop.RmDir.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Stat.Span.cs"
Link="Common\Interop\Unix\Interop.Stat.Span.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UTimensat.cs"
Link="Common\Interop\Unix\Interop.UTimensat.cs" />
<Compile Include="$(CommonPath)System\Text\ValueUtf8Converter.cs"
Link="Common\System\Text\ValueUtf8Converter.cs" />
<Compile Include="$(CommonPath)Interop\OSX\Interop.libobjc.cs"
Link="Interop\OSX\Interop.libobjc.cs" />
<Compile Include="$(CommonPath)Interop\OSX\Interop.Libraries.cs"
Link="Interop\OSX\Interop.Libraries.cs" />
<Compile Include="System\IO\Enumeration\FileSystemEntry.Unix.cs" />
<Compile Include="System\IO\Enumeration\FileSystemEnumerator.Unix.cs" />
<Compile Include="System\IO\FileStatus.OSX.cs" />
<Compile Include="System\IO\FileSystem.Exists.Unix.cs" />
<Compile Include="System\IO\FileSystem.Unix.cs" />
<Compile Include="System\IO\FileSystemInfo.Unix.cs" />
</ItemGroup>
<!-- OSX references -->
<ItemGroup Condition="'$(TargetsOSX)' == 'true'">
<Reference Include="System.Threading" />
</ItemGroup>
</Project>
Loading