Skip to content

Preview 7 Improper LinkTarget returned for a Directory Junction on Windows #57575

@fitdev

Description

@fitdev

When a directory is a junction (as opposed to being a regular directory or a symlink) on Windows, as of Preview 7, DirectoryInfo.LinkTarget returns a non-null value, which is wrong. Considering a structure like this:

C:\Test\RealFolder
C:\Test\JunctionToRealFolder -> C:\Test\RealFolder
C:\Test\SymlinkToRealFolder -> C:\Test\RealFolder

DirectoryInfo.LinkTarget for C:\Test\JunctionToRealFolder returns \Test\RealFolder (instead of C:\Test\RealFolder)
DirectoryInfo.LinkTarget for C:\Test\SymlinkToRealFolder returns C:\Test\RealFolder (which is correct)

Strangely, DirectoryInfo.ResolveLinkTarget(returnFinalTarget: true) returns the correct target in all cases (Junction and Symlink).

I suspect the issue comes that you have an incorrect check for a reparse tag kind in your code:

if ((rdb.ReparseTag & Interop.Kernel32.IOReparseOptions.IO_REPARSE_TAG_SYMLINK) == 0)

Should instead be:

if (rdb.ReparseTag != Interop.Kernel32.IOReparseOptions.IO_REPARSE_TAG_SYMLINK)

Since you say you support symlinks only ATM.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions