Skip to content

Commit

Permalink
Remove symlink specific code from this PR
Browse files Browse the repository at this point in the history
Removes the symlink specific code as per dotnet#49555 (comment).
This will be reverted (and modified) as per dotnet#49555 (comment) into dotnet#52639.
  • Loading branch information
hamarb123 committed Sep 7, 2021
1 parent 17868b1 commit f842935
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 75 deletions.
2 changes: 0 additions & 2 deletions src/libraries/Common/src/Interop/OSX/Interop.libc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/System.Native/pal_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 0 additions & 35 deletions src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public abstract class BaseGetSetTimes<T> : FileSystemTest

protected abstract T GetExistingItem();
protected abstract T GetMissingItem();
protected abstract T CreateSymlinkToItem(T item);

protected abstract string GetItemPath(T item);

Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,5 @@ public override IEnumerable<TimeFunction> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,5 @@ public override IEnumerable<TimeFunction> 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;
}
}
}
8 changes: 0 additions & 8 deletions src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ public override IEnumerable<TimeFunction> 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()
Expand Down
10 changes: 0 additions & 10 deletions src/libraries/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ public override IEnumerable<TimeFunction> 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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f842935

Please sign in to comment.