Skip to content

Commit

Permalink
Fix setting creation date for OSX - revert windows changes & simplify…
Browse files Browse the repository at this point in the history
… code

Revert the changes for Windows & disable the SettingUpdatesPropertiesOnSymlink test on Windows.
Remove unnecessary setting to 0 on the attrList variable.
Remove the unnecessary MarshalAs attributes in the AttrList type.

Fix for #39132 and issues in #49555.
  • Loading branch information
hamarb123 committed Mar 23, 2021
1 parent b85f323 commit a617a01
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/libraries/Common/src/Interop/OSX/Interop.libc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ 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 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ internal partial class FileOperations
internal const int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
internal const int FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000;
internal const int FILE_FLAG_OVERLAPPED = 0x40000000;
internal const int FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;

internal const int FILE_LIST_DIRECTORY = 0x0001;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ internal unsafe void SetCreationTime(string path, DateTimeOffset time)

Interop.libc.AttrList attrList = default;
attrList.bitmapCount = Interop.libc.AttrList.ATTR_BIT_MAP_COUNT;
attrList.reserved = 0;
attrList.commonAttr = Interop.libc.AttrList.ATTR_CMN_CRTIME;
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static SafeFileHandle OpenHandle(string fullPath, bool asDirectory)
Interop.Kernel32.GenericOperations.GENERIC_WRITE,
FileShare.ReadWrite | FileShare.Delete,
FileMode.Open,
(asDirectory ? Interop.Kernel32.FileOperations.FILE_FLAG_BACKUP_SEMANTICS : 0) | Interop.Kernel32.FileOperations.FILE_FLAG_OPEN_REPARSE_POINT);
asDirectory ? Interop.Kernel32.FileOperations.FILE_FLAG_BACKUP_SEMANTICS : 0);

if (handle.IsInvalid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void SettingUpdatesPropertiesAfterAnother()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)]
[PlatformSpecific(~(TestPlatforms.Browser | TestPlatforms.Windows))]
public void SettingUpdatesPropertiesOnSymlink()
{
// This test makes sure that the times are set on the symlink itself.
Expand Down

0 comments on commit a617a01

Please sign in to comment.