diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileStatus.Unix.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileStatus.Unix.cs index 3b638448ac3e6..98ff781432f5b 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileStatus.Unix.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileStatus.Unix.cs @@ -264,6 +264,12 @@ private unsafe void SetAccessOrWriteTime(string path, DateTimeOffset time, bool const long TicksPerSecond = TicksPerMillisecond * 1000; long nanoseconds = (time.UtcDateTime.Ticks - DateTimeOffset.UnixEpoch.Ticks - seconds * TicksPerSecond) * NanosecondsPerTick; +#if TARGET_BROWSER + buf[0].TvSec = seconds; + buf[0].TvNsec = nanoseconds; + buf[1].TvSec = seconds; + buf[1].TvNsec = nanoseconds; +#else if (isAccessTime) { buf[0].TvSec = seconds; @@ -278,9 +284,8 @@ private unsafe void SetAccessOrWriteTime(string path, DateTimeOffset time, bool buf[1].TvSec = seconds; buf[1].TvNsec = nanoseconds; } - +#endif Interop.CheckIo(Interop.Sys.UTimensat(path, buf), path, InitiallyDirectory); - _fileStatusInitialized = -1; } @@ -301,6 +306,7 @@ public void Refresh(ReadOnlySpan path) // lstat fails, as a broken symlink should still report info on exists, attributes, etc. _isDirectory = false; path = Path.TrimEndingDirectorySeparator(path); + int result = Interop.Sys.LStat(path, out _fileStatus); if (result < 0) { diff --git a/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs index 67d9655b1fee5..a959e317682f4 100644 --- a/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs @@ -16,7 +16,9 @@ public abstract class BaseGetSetTimes : FileSystemTest private static string driveFormat = PlatformDetection.IsInAppContainer ? string.Empty : new DriveInfo(Path.GetTempPath()).DriveFormat; protected static bool isHFS => driveFormat != null && driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase); - protected static bool isNotHFS => !isHFS; + + protected static bool LowTemporalResolution => PlatformDetection.IsBrowser || isHFS; + protected static bool HighTemporalResolution => !LowTemporalResolution; protected abstract T GetExistingItem(); protected abstract T GetMissingItem(); @@ -41,7 +43,6 @@ public static TimeFunction Create(SetTime setter, GetTime getter, DateTimeKind k } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/40528", TestPlatforms.Browser)] public void SettingUpdatesProperties() { T item = GetExistingItem(); @@ -49,7 +50,8 @@ public void SettingUpdatesProperties() Assert.All(TimeFunctions(requiresRoundtripping: true), (function) => { // Checking that milliseconds are not dropped after setter. - DateTime dt = new DateTime(2014, 12, 1, 12, 3, 3, isHFS ? 0 : 321, function.Kind); + // Emscripten drops milliseconds in Browser + DateTime dt = new DateTime(2014, 12, 1, 12, 3, 3, LowTemporalResolution ? 0 : 321, function.Kind); function.Setter(item, dt); DateTime result = function.Getter(item); Assert.Equal(dt, result); @@ -77,8 +79,7 @@ public void CanGetAllTimesAfterCreation() ValidateSetTimes(item, beforeTime, afterTime); } - [ConditionalFact(nameof(isNotHFS))] // OSX HFS driver format does not support millisec granularity - [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)] + [ConditionalFact(nameof(HighTemporalResolution))] // OSX HFS driver format and Browser platform do not support millisec granularity public void TimesIncludeMillisecondPart() { T item = GetExistingItem(); @@ -110,11 +111,11 @@ public void TimesIncludeMillisecondPart() }); } - [ConditionalFact(nameof(isHFS))] - public void TimesIncludeMillisecondPart_HFS() + [ConditionalFact(nameof(LowTemporalResolution))] + public void TimesIncludeMillisecondPart_LowTempRes() { T item = GetExistingItem(); - // OSX HFS driver format does not support millisec granularity + // OSX HFS driver format and Browser do not support millisec granularity Assert.All(TimeFunctions(), (function) => { DateTime time = function.Getter(item); diff --git a/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs index 07140ac9c4ee5..86e9504f2b311 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs @@ -134,8 +134,7 @@ public void SetLastWriteTimeTicks() Assert.True(firstFileTicks <= secondFileTicks, $"First File Ticks\t{firstFileTicks}\nSecond File Ticks\t{secondFileTicks}"); } - [ConditionalFact(nameof(isNotHFS))] // OSX HFS driver format does not support nanosecond granularity. - [ActiveIssue("https://github.com/dotnet/runtime/issues/40532", TestPlatforms.Browser)] + [ConditionalFact(nameof(HighTemporalResolution))] // OSX HFS driver format/Browser Platform do not support nanosecond granularity. public void SetUptoNanoseconds() { string file = GetTestFilePath(); diff --git a/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs index 27b2e845868bc..d3b9764951cbf 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs @@ -103,8 +103,7 @@ public override IEnumerable TimeFunctions(bool requiresRoundtrippi DateTimeKind.Utc); } - [ConditionalFact(nameof(isNotHFS))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)] + [ConditionalFact(nameof(HighTemporalResolution))] public void CopyToMillisecondPresent() { FileInfo input = GetNonZeroMilliseconds(); @@ -118,8 +117,7 @@ public void CopyToMillisecondPresent() Assert.NotEqual(0, output.LastWriteTime.Millisecond); } - [ConditionalFact(nameof(isNotHFS))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)] + [ConditionalFact(nameof(HighTemporalResolution))] public void CopyToNanosecondsPresent() { FileInfo input = GetNonZeroNanoseconds(); @@ -135,8 +133,8 @@ public void CopyToNanosecondsPresent() Assert.True(HasNonZeroNanoseconds(output.LastWriteTime)); } - [ConditionalFact(nameof(isHFS))] - public void CopyToNanosecondsPresent_HFS() + [ConditionalFact(nameof(LowTemporalResolution))] + public void CopyToNanosecondsPresent_LowTempRes() { FileInfo input = new FileInfo(GetTestFilePath()); input.Create().Dispose(); @@ -149,8 +147,8 @@ public void CopyToNanosecondsPresent_HFS() Assert.False(HasNonZeroNanoseconds(output.LastWriteTime)); } - [ConditionalFact(nameof(isHFS))] - public void MoveToMillisecondPresent_HFS() + [ConditionalFact(nameof(LowTemporalResolution))] + public void MoveToMillisecondPresent_LowTempRes() { FileInfo input = new FileInfo(GetTestFilePath()); input.Create().Dispose(); @@ -161,8 +159,7 @@ public void MoveToMillisecondPresent_HFS() Assert.Equal(0, output.LastWriteTime.Millisecond); } - [ConditionalFact(nameof(isNotHFS))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/40530", TestPlatforms.Browser)] + [ConditionalFact(nameof(HighTemporalResolution))] public void MoveToMillisecondPresent() { FileInfo input = GetNonZeroMilliseconds(); @@ -173,8 +170,8 @@ public void MoveToMillisecondPresent() Assert.NotEqual(0, output.LastWriteTime.Millisecond); } - [ConditionalFact(nameof(isHFS))] - public void CopyToMillisecondPresent_HFS() + [ConditionalFact(nameof(LowTemporalResolution))] + public void CopyToMillisecondPresent_LowTempRes() { FileInfo input = new FileInfo(GetTestFilePath()); input.Create().Dispose();