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
Fix build failure. Address documentation suggestions.
  • Loading branch information
carlossanlop authored and jozkee committed Jul 2, 2021
commit abbecf01ac0c5693e5abe3467756e8fa1f1040af
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ internal static partial class Interop
internal static partial class Kernel32
{
// https://docs.microsoft.com/windows-hardware/drivers/ifs/fsctl-get-reparse-point
public const int MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024;
internal const int MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024;

public const uint SYMLINK_FLAG_RELATIVE = 1;
internal const uint SYMLINK_FLAG_RELATIVE = 1;

// https://msdn.microsoft.com/library/windows/hardware/ff552012.aspx
// We don't need all the struct fields; omitting the rest.
[StructLayout(LayoutKind.Sequential)]
public unsafe struct REPARSE_DATA_BUFFER
internal unsafe struct REPARSE_DATA_BUFFER
{
public uint ReparseTag;
public ushort ReparseDataLength;
public ushort Reserved;
public SymbolicLinkReparseBuffer ReparseBufferSymbolicLink;
internal uint ReparseTag;
internal ushort ReparseDataLength;
internal ushort Reserved;
internal SymbolicLinkReparseBuffer ReparseBufferSymbolicLink;

[StructLayout(LayoutKind.Sequential)]
public struct SymbolicLinkReparseBuffer
internal struct SymbolicLinkReparseBuffer
{
public ushort SubstituteNameOffset;
public ushort SubstituteNameLength;
public ushort PrintNameOffset;
public ushort PrintNameLength;
public uint Flags;
internal ushort SubstituteNameOffset;
internal ushort SubstituteNameLength;
internal ushort PrintNameOffset;
internal ushort PrintNameLength;
internal uint Flags;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@
Link="Common\Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Close.cs"
Link="Common\Interop\Unix\Interop.Close.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.DefaultPathBufferSize.cs"
Link="Common\Interop\Unix\Interop.DefaultPathBufferSize.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetHostName.cs"
Link="Common\Interop\Unix\Interop.GetHostName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SysConf.cs"
Expand Down Expand Up @@ -261,6 +263,8 @@
Link="Common\Interop\Unix\Interop.ResourceLimits.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.PathConf.cs"
Link="Common\Interop\Unix\Interop.PathConf.cs" />
<Compile Include="$(CommonPath)System\Text\ValueUtf8Converter.cs"
Link="Common\System\Text\ValueUtf8Converter.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.WaitId.cs"
Link="Common\Interop\Unix\Interop.WaitId.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.WaitPid.cs"
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/System.Net.Ping/src/System.Net.Ping.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<Compile Include="$(CommonPath)System\Net\NetworkInformation\UnixCommandLinePing.cs"
Link="Common\System\Net\NetworkInformation\UnixCommandLinePing.cs" />
<!-- Interop -->
<Compile Include="$(CommonPath)Interop\Unix\Interop.DefaultPathBufferSize.cs"
Link="Common\Interop\Unix\Interop.DefaultPathBufferSize.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Link="Common\Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
Expand All @@ -58,6 +60,8 @@
Link="Common\Interop\Unix\System.Native\Interop.Socket.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SocketAddress.cs"
Link="Common\Interop\Unix\System.Native\Interop.SocketAddress.cs" />
<Compile Include="$(CommonPath)System\Text\ValueUtf8Converter.cs"
Link="Common\System\Text\ValueUtf8Converter.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true' AND '$(TargetsApple)' != 'true'">
<Compile Include="System\Net\NetworkInformation\Ping.Unix.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2660,7 +2660,7 @@
<value>BindHandle for ThreadPool failed on this handle.</value>
</data>
<data name="IO_InconsistentLinkType" xml:space="preserve">
<value>The link file system type is inconsistent with the link target system type.</value>
<value>The link's file system entry type is inconsistent with that of its target.</value>
</data>
<data name="IO_FileExists_Name" xml:space="preserve">
<value>The file '{0}' already exists.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,13 @@ public static FileSystemInfo CreateSymbolicLink(string path, string pathToTarget
/// </summary>
/// <param name="linkPath">The path of the directory link.</param>
/// <param name="returnFinalTarget"><see langword="true"/> to follow links to the final target; <see langword="false"/> to return the immediate next link.</param>
/// <returns>A <see cref="DirectoryInfo"/> instance if <paramref name="linkPath"/> exists, independently if the target exists or not. <see langword="null"/> if <paramref name="linkPath"/> does not exist.</returns>
/// <returns>A <see cref="DirectoryInfo"/> instance if <paramref name="linkPath"/> exists, independently if the target exists or not. <see langword="null"/> if <paramref name="linkPath"/> is not a link.</returns>
/// <exception cref="IOException">The directory on <paramref name="linkPath"/> does not exist.
/// -or-
/// The link's file system entry type is inconsistent with that of its target.
/// -or-
/// Too many levels of symbolic links.</exception>
/// <remarks>When <paramref name="returnFinalTarget"/> is <see langword="true"/>, the maximum number of symbolic links that are followed are 40 on Unix.</remarks>
public static System.IO.FileSystemInfo? ResolveLinkTarget(string linkPath, bool returnFinalTarget = false)
{
FileSystem.VerifyValidPath(linkPath, nameof(linkPath));
Expand Down
12 changes: 8 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/IO/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,9 +1017,7 @@ private static async Task InternalWriteAllTextAsync(StreamWriter sw, string cont
/// <exception cref="ArgumentNullException"><paramref name="path"/> or <paramref name="pathToTarget"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="path"/> or <paramref name="pathToTarget"/> is empty.
/// -or-
/// <paramref name="path"/> is not an absolute path.
/// -or-
/// <paramref name="path"/> or <paramref name="pathToTarget"/> contains invalid path characters.</exception>
/// <paramref name="path"/> or <paramref name="pathToTarget"/> contains a null character.</exception>
/// <exception cref="IOException">A file or directory already exists in the location of <paramref name="path"/>.
/// -or-
/// An I/O error occurred.</exception>
Expand All @@ -1036,7 +1034,13 @@ public static FileSystemInfo CreateSymbolicLink(string path, string pathToTarget
/// </summary>
/// <param name="linkPath">The path of the file link.</param>
/// <param name="returnFinalTarget"><see langword="true"/> to follow links to the final target; <see langword="false"/> to return the immediate next link.</param>
/// <returns>A <see cref="FileInfo"/> instance if <paramref name="linkPath"/> exists, independently if the target exists or not. <see langword="null"/> if <paramref name="linkPath"/> does not exist.</returns>
/// <returns>A <see cref="FileInfo"/> instance if <paramref name="linkPath"/> exists, independently if the target exists or not. <see langword="null"/> if <paramref name="linkPath"/> is not a link.</returns>
/// <exception cref="IOException">The file on <paramref name="linkPath"/> does not exist.
/// -or-
/// The link's file system entry type is inconsistent with that of its target.
/// -or-
/// Too many levels of symbolic links.</exception>
/// <remarks>When <paramref name="returnFinalTarget"/> is <see langword="true"/>, the maximum number of symbolic links that are followed are 40 on Unix.</remarks>
public static System.IO.FileSystemInfo? ResolveLinkTarget(string linkPath, bool returnFinalTarget = false)
{
FileSystem.VerifyValidPath(linkPath, nameof(linkPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ internal static void CreateSymbolicLink(string path, string pathToTarget, bool i
/// <param name="isDirectory">True if the linkPath points to a directory or a symlink to a directory.</param>
/// <returns>If the specified linkPath represents a link file and it exists, returns a FileInfo if isDirectory
/// is false, or a DirectoryInfo if isDirectory is true, independently if the target file/directory exists or not.
/// If the specified linkPath is not a link file or it does not exist, returns null.</returns>
/// If the specified linkPath is not a link, returns null. Throws if the file or directory in linkPath does not exist.</returns>
internal static FileSystemInfo? ResolveLinkTarget(string linkPath, bool returnFinalTarget, bool isDirectory)
{
// throws if the current link file does not exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ public void CreateAsSymbolicLink(string pathToTarget)
/// Gets the target of the specified link.
/// </summary>
/// <param name="returnFinalTarget"><see langword="true"/> to follow links to the final target; <see langword="false"/> to return the immediate next link.</param>
/// <returns>A <see cref="FileSystemInfo"/> instance if the link exists, independently if the target exists or not; <see langword="null"/> if a link does not exist
/// in <see cref="FullName"/>, or this instance does not represent a link.</returns>
/// <returns>A <see cref="FileSystemInfo"/> instance if the link exists, independently if the target exists or not; <see langword="null"/> if this file or directory is not a link.</returns>
/// <exception cref="IOException">The file or directory does not exist.
/// -or-
/// The link's file system entry type is inconsistent with that of its target.
/// -or-
/// Too many levels of symbolic links.</exception>
/// <remarks>When <paramref name="returnFinalTarget"/> is <see langword="true"/>, the maximum number of symbolic links that are followed are 40 on Unix.</remarks>
public FileSystemInfo? ResolveLinkTarget(bool returnFinalTarget = false) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamsitnik as mentioned in #24271 (comment), I think the appropriate default is true here.

Imo it's more interesting to figure out the canonical path than what this method will give you. This was proposed as a method on Path in #24271 (comment) and refined by @mklement0 in #24271 (comment).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the appropriate default is true here

I agree. @jozkee should we just change it before it gets merged so we don't need to introduce breaking changes in the future?

FileSystem.ResolveLinkTarget(FullPath, returnFinalTarget, this is DirectoryInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,14 @@
Link="Common\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Link="Common\Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.DefaultPathBufferSize.cs"
Link="Common\Interop\Unix\Interop.DefaultPathBufferSize.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Permissions.cs"
Link="Common\Interop\Unix\System.Native\Interop.Permissions.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.ReadLink.cs"
Link="Common\Interop\Unix\System.Native\Interop.ReadLink.cs" />
<Compile Include="$(CommonPath)System\Text\ValueUtf8Converter.cs"
Link="Common\System\Text\ValueUtf8Converter.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Security.Cryptography.Native\Interop.ASN1.cs"
Link="Common\Interop\Unix\System.Security.Cryptography.Native\Interop.ASN1.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Security.Cryptography.Native\Interop.ASN1.GetIntegerBytes.cs"
Expand Down