Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b63c7b7
ref declarations and src empty definitions
carlossanlop Jun 1, 2021
b223304
Implementation for Unix symlinks APIs and cross-platform unit tests.
carlossanlop Jun 1, 2021
2e822fd
Add windows implementation of [sym]link APIs
jozkee Jun 11, 2021
32e196c
Use ValueStringBuilder in ResolveLinkTarget
carlossanlop Jun 15, 2021
8ed2772
Build failure in FileSystemWatcher csproj due to missing new interop …
carlossanlop Jun 17, 2021
abbecf0
Fix build failure. Address documentation suggestions.
Jun 17, 2021
fc49855
Add missing csproj references to System.Net.Ping.Functional.Tests (pr…
carlossanlop Jun 18, 2021
86cbd19
Move CanCreateSymbolicLinks from FileSystemWatcher one class above, s…
Jun 18, 2021
480d3df
Fix some Microsoft.IO.Redist CI failures.
carlossanlop Jun 18, 2021
a6cd9da
Fix CI build failures from Net5Compat.Tests
carlossanlop Jun 18, 2021
6952eb7
Clean CanCreateSymbolicLinks for readability. Remove incomplete code.
carlossanlop Jun 21, 2021
797ace5
Support long paths in GetFinalPathNameByHandle
jozkee Jun 18, 2021
8639e3b
Use MS.IO.Redist friendly APIs for marshalling
jozkee Jun 19, 2021
6bb1aa9
Add IsBrowser check to CanCreateSymbolicLinks
carlossanlop Jun 21, 2021
88bcadb
Add more tests and fix some issues in windows
jozkee Jun 22, 2021
8701118
Add path to IO_InconsistentLinkType exception msg
carlossanlop Jun 22, 2021
d10e00c
Fix failure in test creating inconsistent file/dir type.
carlossanlop Jun 22, 2021
fa5ff40
Fix net48 error
jozkee Jun 22, 2021
6788db7
Address CreateSymbolicLink initial check on Unix to verify pathToTarg…
Jun 22, 2021
45392b4
Use RemoteExecutor for a test related to change the current working dir
jozkee Jun 23, 2021
38b6e88
Add missing argument to exception message in MS.IO.Redist
Jun 23, 2021
a70cdef
nit: Clean comment on CreateSymbolicLink p/invoke.
Jun 23, 2021
cbcf7af
Fix CI bug in Windows Nano where %TEMP% points to "C:\Windows\TEMP" b…
carlossanlop Jun 26, 2021
c43664a
Use ALLOW_UNPRIVILEGED_CREATE only on windows versions >= 10.0.14972
jozkee Jun 26, 2021
9460264
Do not use IsWindowsVersionAtLeast since isn't avail in ns2.0
jozkee Jun 28, 2021
bbaa35a
Use PrintName (Dos) instead of SubstituteName (NT)
jozkee Jun 28, 2021
7e2eaa9
Fix issues related to server share paths
jozkee Jun 29, 2021
0d4250b
Fix CI issues
jozkee Jun 29, 2021
1a05a56
Address suggestions
jozkee Jun 29, 2021
d656aed
Address suggestions
jozkee Jun 29, 2021
adcca16
Address suggestions about using PathInternal.IsExtended
jozkee Jun 29, 2021
35165b0
Add more scenarios for "file system entry type is inconsistent with t…
jozkee Jul 1, 2021
9d2694b
Remove duplicated validation checks
jozkee Jul 1, 2021
c79df26
Address suggestions for Unix
jozkee Jul 1, 2021
fc4241d
ifdef the list of paths used for theories
jozkee Jul 1, 2021
4881f2b
Add tests to verify the limit of followed links
jozkee Jul 2, 2021
b377cb0
Fix bug related to follow links limit in Unix
jozkee Jul 2, 2021
496487f
Trim extended prefix when the passed-in path is not extended
jozkee Jul 2, 2021
beaf701
Remove helper AssertFullNameEquals since is no longer needed and fix …
jozkee Jul 2, 2021
a5986fb
Add a check for versions < win10 build 14972 to fix silent error
jozkee Jul 2, 2021
b7ec269
Add Windows limit for ResolveLinkTarget to remarks
jozkee Jul 2, 2021
7f37a86
Remove pipe test
jozkee Jul 2, 2021
3e36f72
Remove lstat from ResolveLinkTarget
jozkee Jul 6, 2021
6f5b99a
Avoid testing the reparse point/soft link limit very precisely
jozkee Jul 8, 2021
2d09f7e
Fix LinkTarget invalidation logic
jozkee Jul 8, 2021
4b5e133
Make returnFinalTarget no longer optional
jozkee Jul 8, 2021
82dc88a
Merge branch 'main' of https://github.com/dotnet/runtime into symlinks
jozkee Jul 8, 2021
48e1af1
Try to fix failing tests found in CI
jozkee Jul 8, 2021
0495f59
Try smaller chains of links
jozkee Jul 8, 2021
40cb737
Avoid using GetTestFilePath in order to correctly compare against the…
jozkee Jul 9, 2021
995ead5
Use chain length of 20 instead of 30, which fails in Win 1809
jozkee Jul 9, 2021
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
Prev Previous commit
Next Next commit
Use PrintName (Dos) instead of SubstituteName (NT)
  • Loading branch information
jozkee committed Jul 2, 2021
commit bbaa35ac2d7c2c1da7ec101335c0ad99504a0ce9
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,6 @@ public abstract class BaseSymbolicLinks_FileSystem : BaseSymbolicLinks
/// <summary>Calls the actual public API for resolving the symbolic link target.</summary>
protected abstract FileSystemInfo ResolveLinkTarget(string linkPath, bool returnFinalTarget = false);

/// <summary>
/// Verifies that FileSystemInfo.LinkTarget matches the specified expected path.
/// If the current platform is Windows and <paramref name="actual"/> is absolute, this method asserts that <paramref name="actual"/> starts with \\?\.
/// </summary>
protected static void AssertLinkTargetEquals(string expected, string actual)
{
#if WINDOWS
if (Path.IsPathFullyQualified(actual))
{
actual.StartsWith(ExtendedPrefix);
expected = Path.Join(ExtendedPrefix, expected);
}

// Windows syscalls remove the redundant segments in the link target path.
// We will remove them from the expected path when testing Windows but keep them when testing Unix, which doesn't remove them.
int rootLength = PathInternal.GetRootLength(expected);
if (rootLength > 0)
{
expected = PathInternal.RemoveRelativeSegments(expected, rootLength);
}
#endif
Assert.Equal(expected, actual);
}


/// <summary>
/// Asserts that the FullPath of the FileSystemInfo returned by ResolveLinkTarget() matches with the expected path of the file created.
/// Trims the Windows device prefix, in case there's any, before comparing.
Expand Down Expand Up @@ -188,7 +163,7 @@ public void ResolveLinkTarget_Succeeds(string pathToTarget, bool returnFinalTarg
FileSystemInfo linkInfo = CreateSymbolicLink(linkPath, pathToTarget);
AssertLinkExists(linkInfo);
AssertIsCorrectTypeAndDirectoryAttribute(linkInfo);
AssertLinkTargetEquals(pathToTarget, linkInfo.LinkTarget);
Assert.Equal(pathToTarget, linkInfo.LinkTarget);

FileSystemInfo targetInfo = ResolveLinkTarget(linkPath, returnFinalTarget);
Assert.NotNull(targetInfo);
Expand Down Expand Up @@ -379,22 +354,22 @@ private void ResolveLinkTarget_ReturnFinalTarget(string link1Path, string link1T
Assert.True(link2Info.Exists);
Assert.True(link2Info.Attributes.HasFlag(FileAttributes.ReparsePoint));
AssertIsCorrectTypeAndDirectoryAttribute(link2Info);
AssertLinkTargetEquals(link2Target, link2Info.LinkTarget);
Assert.Equal(link2Target, link2Info.LinkTarget);

// link1 to link2
FileSystemInfo link1Info = CreateSymbolicLink(link1Path, link1Target);
Assert.True(link1Info.Exists);
Assert.True(link1Info.Attributes.HasFlag(FileAttributes.ReparsePoint));
AssertIsCorrectTypeAndDirectoryAttribute(link1Info);
AssertLinkTargetEquals(link1Target, link1Info.LinkTarget);
Assert.Equal(link1Target, link1Info.LinkTarget);

// link1: do not follow symlinks
FileSystemInfo link1TargetInfo = ResolveLinkTarget(link1Path);
Assert.True(link1TargetInfo.Exists);
AssertIsCorrectTypeAndDirectoryAttribute(link1TargetInfo);
Assert.True(link1TargetInfo.Attributes.HasFlag(FileAttributes.ReparsePoint));
AssertFullNameEquals(link2Path, link1TargetInfo.FullName);
AssertLinkTargetEquals(link2Target, link1TargetInfo.LinkTarget);
Assert.Equal(link2Target, link1TargetInfo.LinkTarget);

// link2: do not follow symlinks
FileSystemInfo link2TargetInfo = ResolveLinkTarget(link2Path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void LinkTarget_Succeeds(string pathToTarget)
FileSystemInfo linkInfo = CreateSymbolicLink(GetRandomLinkPath(), pathToTarget);

AssertLinkExists(linkInfo);
AssertLinkTargetEquals(pathToTarget, linkInfo.LinkTarget);
Assert.Equal(pathToTarget, linkInfo.LinkTarget);
}

public static IEnumerable<object[]> LinkTarget_PathToTarget_Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ internal static void CreateSymbolicLink(string path, string pathToTarget, bool i
}
}

byte[]? buffer = ArrayPool<byte>.Shared.Rent(Interop.Kernel32.MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
byte[] buffer = ArrayPool<byte>.Shared.Rent(Interop.Kernel32.MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
try
{
bool success = Interop.Kernel32.DeviceIoControl(
Expand Down Expand Up @@ -503,21 +503,18 @@ internal static void CreateSymbolicLink(string path, string pathToTarget, bool i
return null;
}

int substituteNameOffset = sizeof(Interop.Kernel32.REPARSE_DATA_BUFFER) + rdb.ReparseBufferSymbolicLink.SubstituteNameOffset;
int substituteNameLength = rdb.ReparseBufferSymbolicLink.SubstituteNameLength;
// We use PrintName instead of SubstitutneName given that we don't want to return a NT path.
// Unlike SubstituteName and GetFinalPathNameByHandle(), PrintName doesn't start with a prefix.
// Another nuance is that SubstituteName does not contain redundant path segments while PrintName does.
int printNameNameOffset = sizeof(Interop.Kernel32.REPARSE_DATA_BUFFER) + rdb.ReparseBufferSymbolicLink.PrintNameOffset;
int printNameNameLength = rdb.ReparseBufferSymbolicLink.PrintNameLength;

Span<char> targetPath = MemoryMarshal.Cast<byte, char>(bufferSpan.Slice(substituteNameOffset, substituteNameLength));
Span<char> targetPath = MemoryMarshal.Cast<byte, char>(bufferSpan.Slice(printNameNameOffset, printNameNameLength));
Debug.Assert(Path.IsPathFullyQualified(targetPath));
Debug.Assert((rdb.ReparseBufferSymbolicLink.Flags & Interop.Kernel32.SYMLINK_FLAG_RELATIVE) == 0 ||
targetPath.Length >= 4 && !targetPath.StartsWith(PathInternal.ExtendedPathPrefix) && !targetPath.StartsWith(@"\??\"));

if ((rdb.ReparseBufferSymbolicLink.Flags & Interop.Kernel32.SYMLINK_FLAG_RELATIVE) == 0)
{
// Target path is absolute.
// DeviceIoControl returns a DOS Device path (\??\) which many APIs don't tolerate.
// We should instead return a Win32 path (\\?\).
Debug.Assert(Path.IsPathFullyQualified(targetPath));
Debug.Assert(targetPath[1] == '?');
targetPath[1] = '\\';
}
else if (normalize)
if (normalize && (rdb.ReparseBufferSymbolicLink.Flags & Interop.Kernel32.SYMLINK_FLAG_RELATIVE) != 0)
{
// Target path is relative and is for ResolveLinkTarget(), we need to append the link directory.
return Path.Join(Path.GetDirectoryName(linkPath.AsSpan()), targetPath);
Expand All @@ -527,10 +524,7 @@ internal static void CreateSymbolicLink(string path, string pathToTarget, bool i
}
finally
{
if (buffer != null)
{
ArrayPool<byte>.Shared.Return(buffer);
}
ArrayPool<byte>.Shared.Return(buffer);
}
}

Expand Down