From f84293583bb0c8e1060bdacfb80158a6c64c5fbd Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Wed, 8 Sep 2021 09:08:11 +1000 Subject: [PATCH] Remove symlink specific code from this PR Removes the symlink specific code as per https://github.com/dotnet/runtime/pull/49555#issuecomment-904413721. This will be reverted (and modified) as per https://github.com/dotnet/runtime/pull/49555#issuecomment-904413721 into #52639. --- .../Common/src/Interop/OSX/Interop.libc.cs | 2 -- .../Native/Unix/System.Native/pal_time.c | 2 +- .../tests/Base/BaseGetSetTimes.cs | 35 ------------------- .../tests/Directory/GetSetTimes.cs | 8 ----- .../tests/DirectoryInfo/GetSetTimes.cs | 10 ------ .../tests/File/GetSetTimes.cs | 8 ----- .../tests/FileInfo/GetSetTimes.cs | 10 ------ .../src/System/IO/FileStatus.OSX.cs | 2 +- 8 files changed, 2 insertions(+), 75 deletions(-) diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libc.cs index 89ba51305689f..d0b377977a1d6 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.libc.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.libc.cs @@ -25,7 +25,5 @@ internal struct AttrList [DllImport(Libraries.libc, EntryPoint = "setattrlist", SetLastError = true)] internal static unsafe extern int setattrlist(string path, AttrList* attrList, void* attrBuf, nint attrBufSize, CULong options); - - internal const uint FSOPT_NOFOLLOW = 0x00000001; } } diff --git a/src/libraries/Native/Unix/System.Native/pal_time.c b/src/libraries/Native/Unix/System.Native/pal_time.c index ef8a27a175c0f..56e23138a7b77 100644 --- a/src/libraries/Native/Unix/System.Native/pal_time.c +++ b/src/libraries/Native/Unix/System.Native/pal_time.c @@ -33,7 +33,7 @@ int32_t SystemNative_UTimensat(const char* path, TimeSpec* times) updatedTimes[1].tv_sec = (time_t)times[1].tv_sec; updatedTimes[1].tv_nsec = (long)times[1].tv_nsec; - while (CheckInterrupted(result = utimensat(AT_FDCWD, path, updatedTimes, AT_SYMLINK_NOFOLLOW))); + while (CheckInterrupted(result = utimensat(AT_FDCWD, path, updatedTimes, 0))); #else struct timeval updatedTimes[2]; updatedTimes[0].tv_sec = (long)times[0].tv_sec; diff --git a/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs index a8d6a052a5436..437f331be1f42 100644 --- a/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs @@ -23,7 +23,6 @@ public abstract class BaseGetSetTimes : FileSystemTest protected abstract T GetExistingItem(); protected abstract T GetMissingItem(); - protected abstract T CreateSymlinkToItem(T item); protected abstract string GetItemPath(T item); @@ -130,40 +129,6 @@ public void SettingUpdatesPropertiesAfterAnother() }); } - [Fact] - [PlatformSpecific(~(TestPlatforms.Browser | TestPlatforms.Windows))] - public void SettingUpdatesPropertiesOnSymlink() - { - // Browser is excluded as there is only 1 effective time store. - - // This test makes sure that the times are set on the symlink itself. - // It is needed as on OSX for example, the default for most APIs is - // to follow the symlink to completion and set the time on that entry - // instead (eg. the setattrlist will do this without the flag set). - T item = CreateSymlinkToItem(GetExistingItem()); - - Assert.All(TimeFunctions(requiresRoundtripping: true), (function) => - { - // Checking that milliseconds are not dropped after setter on supported platforms. - DateTime dt = new DateTime(2004, 12, 1, 12, 3, 3, LowTemporalResolution ? 0 : 321, function.Kind); - function.Setter(item, dt); - DateTime result = function.Getter(item); - Assert.Equal(dt, result); - Assert.Equal(dt.ToLocalTime(), result.ToLocalTime()); - - // File and Directory UTC APIs treat a DateTimeKind.Unspecified as UTC whereas - // ToUniversalTime treats it as local. - if (function.Kind == DateTimeKind.Unspecified) - { - Assert.Equal(dt, result.ToUniversalTime()); - } - else - { - Assert.Equal(dt.ToUniversalTime(), result.ToUniversalTime()); - } - }); - } - [Fact] public void CanGetAllTimesAfterCreation() { diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/Directory/GetSetTimes.cs index 7531ccae83019..0a23d638c138a 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/GetSetTimes.cs @@ -51,13 +51,5 @@ public override IEnumerable TimeFunctions(bool requiresRoundtrippi ((path) => Directory.GetLastWriteTimeUtc(path)), DateTimeKind.Utc); } - - protected override string CreateSymlinkToItem(string item) - { - var link = item + ".link"; - if (Directory.Exists(link)) Directory.Delete(link); - if (!MountHelper.CreateSymbolicLink(link, item, true) || !Directory.Exists(link)) throw new Exception("Could not create symlink."); - return link; - } } } diff --git a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs index cce3d1853c1d0..2dad268a79a46 100644 --- a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs @@ -57,15 +57,5 @@ public override IEnumerable TimeFunctions(bool requiresRoundtrippi ((testDir) => testDir.LastWriteTimeUtc), DateTimeKind.Utc); } - - protected override DirectoryInfo CreateSymlinkToItem(DirectoryInfo item) - { - var link = new DirectoryInfo(item.FullName + ".link"); - if (link.Exists) link.Delete(); - bool failed = !MountHelper.CreateSymbolicLink(link.FullName, item.FullName, true); - link.Refresh(); - if (failed || !link.Exists) throw new Exception("Could not create symlink."); - return link; - } } } diff --git a/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs index 551a5115106b1..67a13bcf7df2b 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs @@ -103,14 +103,6 @@ public override IEnumerable TimeFunctions(bool requiresRoundtrippi DateTimeKind.Utc); } - protected override string CreateSymlinkToItem(string item) - { - var link = item + ".link"; - if (File.Exists(link)) File.Delete(link); - if (!MountHelper.CreateSymbolicLink(link, item, false) || !File.Exists(link)) throw new Exception("Could not create symlink."); - return link; - } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotInAppContainer))] // Can't read root in appcontainer [PlatformSpecific(TestPlatforms.Windows)] public void PageFileHasTimes() diff --git a/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs index 7abf30a1a20e1..d3b9764951cbf 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs @@ -103,16 +103,6 @@ public override IEnumerable TimeFunctions(bool requiresRoundtrippi DateTimeKind.Utc); } - protected override FileInfo CreateSymlinkToItem(FileInfo item) - { - var link = new FileInfo(item.FullName + ".link"); - if (link.Exists) link.Delete(); - bool failed = !MountHelper.CreateSymbolicLink(link.FullName, item.FullName, false); - link.Refresh(); - if (failed || !link.Exists) throw new Exception("Could not create symlink."); - return link; - } - [ConditionalFact(nameof(HighTemporalResolution))] public void CopyToMillisecondPresent() { diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.OSX.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.OSX.cs index 7f0edeed39804..5be8f88c4fa1c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.OSX.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.OSX.cs @@ -26,7 +26,7 @@ internal unsafe void SetCreationTime(string path, DateTimeOffset time) // 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. - Interop.Error result = (Interop.Error)Interop.libc.setattrlist(path, &attrList, &timeSpec, sizeof(Interop.Sys.TimeSpec), new CULong(Interop.libc.FSOPT_NOFOLLOW)); + Interop.Error result = (Interop.Error)Interop.libc.setattrlist(path, &attrList, &timeSpec, sizeof(Interop.Sys.TimeSpec), default(CULong)); if (result == Interop.Error.ENOTSUP) { SetCreationTime_StandardUnixImpl(path, time);