Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8e7069a
Add mount point support to link APIs.
carlossanlop Aug 24, 2021
11960b4
Add junction and virtual drive tests.
carlossanlop Aug 24, 2021
e59f2b2
Move PrintName comment outside of if else of reparseTag check.
carlossanlop Aug 24, 2021
2923c9e
Add Windows platform specific attribute to junction and virtual drive…
carlossanlop Aug 24, 2021
b6cf857
Revert FILE_NAME_OPENED to FILE_NAME_NORMALIZED
carlossanlop Aug 24, 2021
3ef33c2
Revert addition of FILE_NAME_OPENED const.
carlossanlop Aug 24, 2021
bc12ecf
Remove unnecessary enumeration junction test.
carlossanlop Aug 25, 2021
8957765
Rename GetNewCwdPath to ChangeCurrentDirectory
carlossanlop Aug 25, 2021
ce2aa86
Make Junction_ResolveLinkTarget a theory and test both resolveFinalTa…
carlossanlop Aug 25, 2021
999cddc
Shorter name for targetPath string. Typo in comment. Fix Debug.Assert.
carlossanlop Aug 25, 2021
42fb3a0
Clarify test comment. Change PlatformDetection for OperatingSystem ch…
carlossanlop Aug 25, 2021
ca1f2b2
Cleaner unit tests for virtual drive, add indirection test
carlossanlop Aug 26, 2021
6f6d368
Skip virtual drive tests in Windows Nano (subst not available). Small…
carlossanlop Aug 26, 2021
ec8000b
Simplify Junctions tests, add indirection test
carlossanlop Aug 26, 2021
7df549e
Address test suggestions.
carlossanlop Aug 26, 2021
be9e582
Revert MountHelper.CreateSymbolicLink changes. Unrelated, and will be…
carlossanlop Aug 27, 2021
d33bda3
Add dwReserved0 check for mount points in GetFinalLinkTarget.
carlossanlop Aug 27, 2021
244246b
Use Yoda we don't.
carlossanlop Aug 27, 2021
bd7e9cc
Fix CI issues
jozkee Aug 27, 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
Move PrintName comment outside of if else of reparseTag check.
  • Loading branch information
carlossanlop committed Aug 24, 2021
commit e59f2b236740001b6782ebf4768472837b79e4a1
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ protected DirectoryInfo CreateSelfReferencingSymbolicLink()

protected string GetRandomFileName() => GetTestFileName() + ".txt";
protected string GetRandomLinkName() => GetTestFileName() + ".link";
protected string GetRandomDirName() => GetTestFileName() + "_dir";
protected string GetRandomDirName() => GetTestFileName() + "_dir";

protected string GetRandomFilePath() => Path.Join(ActualTestDirectory.Value, GetRandomFileName());
protected string GetRandomLinkPath() => Path.Join(ActualTestDirectory.Value, GetRandomLinkName());
protected string GetRandomDirPath() => Path.Join(ActualTestDirectory.Value, GetRandomDirName());
protected string GetRandomDirPath() => Path.Join(ActualTestDirectory.Value, GetRandomDirName());

private Lazy<string> ActualTestDirectory => new Lazy<string>(() => GetTestDirectoryActualCasing());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,19 @@ internal static void CreateSymbolicLink(string path, string pathToTarget, bool i
success = MemoryMarshal.TryRead(bufferSpan, out Interop.Kernel32.SymbolicLinkReparseBuffer rbSymlink);
Debug.Assert(success);

// We use PrintName(Offset|Length) instead of SubstituteName(Offset|Length) given that we don't want to return
// an NT path when the link wasn't created with such 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.
// PrintName can ONLY return a NT path if the link was created explicitly targeting a file/folder in such way.
// e.g: mklink /D linkName \??\C:\path\to\target.

if (rbSymlink.ReparseTag == Interop.Kernel32.IOReparseOptions.IO_REPARSE_TAG_SYMLINK)
{
// We use PrintName instead of SubstituteName given that we don't want to return a NT path when the link wasn't created with such 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.
// PrintName can ONLY return a NT path if the link was created explicitly targeting a file/folder in such way. e.g: mklink /D linkName \??\C:\path\to\target.

int printNameNameOffset = sizeof(Interop.Kernel32.SymbolicLinkReparseBuffer) + rbSymlink.PrintNameOffset;
int printNameNameLength = rbSymlink.PrintNameLength;
int printNameOffset = sizeof(Interop.Kernel32.SymbolicLinkReparseBuffer) + rbSymlink.PrintNameOffset;
int printNameLength = rbSymlink.PrintNameLength;

Span<char> targetPathSymlink = MemoryMarshal.Cast<byte, char>(bufferSpan.Slice(printNameNameOffset, printNameNameLength));
Span<char> targetPathSymlink = MemoryMarshal.Cast<byte, char>(bufferSpan.Slice(printNameOffset, printNameLength));
Debug.Assert((rbSymlink.Flags & Interop.Kernel32.SYMLINK_FLAG_RELATIVE) == 0 || !PathInternal.IsExtended(targetPathSymlink));

if (returnFullPath && (rbSymlink.Flags & Interop.Kernel32.SYMLINK_FLAG_RELATIVE) != 0)
Expand All @@ -528,12 +530,13 @@ internal static void CreateSymbolicLink(string path, string pathToTarget, bool i
success = MemoryMarshal.TryRead(bufferSpan, out Interop.Kernel32.MountPointReparseBuffer rbMountPoint);
Debug.Assert(success);

int printNameNameOffset = sizeof(Interop.Kernel32.MountPointReparseBuffer) + rbMountPoint.PrintNameOffset;
int printNameNameLength = rbMountPoint.PrintNameLength;
int printNameOffset = sizeof(Interop.Kernel32.MountPointReparseBuffer) + rbMountPoint.PrintNameOffset;
int printNameLength = rbMountPoint.PrintNameLength;

Span<char> targetPathMountPoint = MemoryMarshal.Cast<byte, char>(bufferSpan.Slice(printNameNameOffset, printNameNameLength));
Debug.Assert(!PathInternal.IsExtended(targetPathMountPoint));
Span<char> targetPathMountPoint = MemoryMarshal.Cast<byte, char>(bufferSpan.Slice(printNameOffset, printNameLength));

// Unlink symlinks, mount point paths cannot be relative
Debug.Assert(!PathInternal.IsExtended(targetPathMountPoint));
return targetPathMountPoint.ToString();
}

Expand Down