-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add symbolic link APIs #54253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add symbolic link APIs #54253
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 b223304
Implementation for Unix symlinks APIs and cross-platform unit tests.
carlossanlop 2e822fd
Add windows implementation of [sym]link APIs
jozkee 32e196c
Use ValueStringBuilder in ResolveLinkTarget
carlossanlop 8ed2772
Build failure in FileSystemWatcher csproj due to missing new interop …
carlossanlop abbecf0
Fix build failure. Address documentation suggestions.
fc49855
Add missing csproj references to System.Net.Ping.Functional.Tests (pr…
carlossanlop 86cbd19
Move CanCreateSymbolicLinks from FileSystemWatcher one class above, s…
480d3df
Fix some Microsoft.IO.Redist CI failures.
carlossanlop a6cd9da
Fix CI build failures from Net5Compat.Tests
carlossanlop 6952eb7
Clean CanCreateSymbolicLinks for readability. Remove incomplete code.
carlossanlop 797ace5
Support long paths in GetFinalPathNameByHandle
jozkee 8639e3b
Use MS.IO.Redist friendly APIs for marshalling
jozkee 6bb1aa9
Add IsBrowser check to CanCreateSymbolicLinks
carlossanlop 88bcadb
Add more tests and fix some issues in windows
jozkee 8701118
Add path to IO_InconsistentLinkType exception msg
carlossanlop d10e00c
Fix failure in test creating inconsistent file/dir type.
carlossanlop fa5ff40
Fix net48 error
jozkee 6788db7
Address CreateSymbolicLink initial check on Unix to verify pathToTarg…
45392b4
Use RemoteExecutor for a test related to change the current working dir
jozkee 38b6e88
Add missing argument to exception message in MS.IO.Redist
a70cdef
nit: Clean comment on CreateSymbolicLink p/invoke.
cbcf7af
Fix CI bug in Windows Nano where %TEMP% points to "C:\Windows\TEMP" b…
carlossanlop c43664a
Use ALLOW_UNPRIVILEGED_CREATE only on windows versions >= 10.0.14972
jozkee 9460264
Do not use IsWindowsVersionAtLeast since isn't avail in ns2.0
jozkee bbaa35a
Use PrintName (Dos) instead of SubstituteName (NT)
jozkee 7e2eaa9
Fix issues related to server share paths
jozkee 0d4250b
Fix CI issues
jozkee 1a05a56
Address suggestions
jozkee d656aed
Address suggestions
jozkee adcca16
Address suggestions about using PathInternal.IsExtended
jozkee 35165b0
Add more scenarios for "file system entry type is inconsistent with t…
jozkee 9d2694b
Remove duplicated validation checks
jozkee c79df26
Address suggestions for Unix
jozkee fc4241d
ifdef the list of paths used for theories
jozkee 4881f2b
Add tests to verify the limit of followed links
jozkee b377cb0
Fix bug related to follow links limit in Unix
jozkee 496487f
Trim extended prefix when the passed-in path is not extended
jozkee beaf701
Remove helper AssertFullNameEquals since is no longer needed and fix …
jozkee a5986fb
Add a check for versions < win10 build 14972 to fix silent error
jozkee b7ec269
Add Windows limit for ResolveLinkTarget to remarks
jozkee 7f37a86
Remove pipe test
jozkee 3e36f72
Remove lstat from ResolveLinkTarget
jozkee 6f5b99a
Avoid testing the reparse point/soft link limit very precisely
jozkee 2d09f7e
Fix LinkTarget invalidation logic
jozkee 4b5e133
Make returnFinalTarget no longer optional
jozkee 82dc88a
Merge branch 'main' of https://github.com/dotnet/runtime into symlinks
jozkee 48e1af1
Try to fix failing tests found in CI
jozkee 0495f59
Try smaller chains of links
jozkee 40cb737
Avoid using GetTestFilePath in order to correctly compare against the…
jozkee 995ead5
Use chain length of 20 instead of 30, which fails in Win 1809
jozkee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix CI bug in Windows Nano where %TEMP% points to "C:\Windows\TEMP" b…
…ut the actual folder name is "C:\Windows\Temp", which prevents us from using Assert.Equal for path comparison.
- Loading branch information
commit cbcf7af23f79ab8f11d696760da220e15be88765
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/libraries/System.IO.FileSystem/tests/Base/SymbolicLinks/BaseSymbolicLinks.Browser.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Buffers; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Win32.SafeHandles; | ||
| using Xunit; | ||
|
|
||
| namespace System.IO.Tests | ||
| { | ||
| public abstract partial class BaseSymbolicLinks : FileSystemTest | ||
| { | ||
| private string GetTestDirectoryActualCasing() => TestDirectory; | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/libraries/System.IO.FileSystem/tests/Base/SymbolicLinks/BaseSymbolicLinks.Unix.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Buffers; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Win32.SafeHandles; | ||
| using Xunit; | ||
|
|
||
| namespace System.IO.Tests | ||
| { | ||
| public abstract partial class BaseSymbolicLinks : FileSystemTest | ||
| { | ||
| private string GetTestDirectoryActualCasing() => TestDirectory; | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
src/libraries/System.IO.FileSystem/tests/Base/SymbolicLinks/BaseSymbolicLinks.Windows.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Buffers; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Win32.SafeHandles; | ||
| using Xunit; | ||
|
|
||
| namespace System.IO.Tests | ||
| { | ||
| public abstract partial class BaseSymbolicLinks : FileSystemTest | ||
| { | ||
| private const int OPEN_EXISTING = 3; | ||
| private const int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; | ||
|
|
||
| // Some Windows versions like Windows Nano Server have the %TEMP% environment variable set to "C:\TEMP" but the | ||
| // actual folder name is "C:\Temp", which prevents asserting path values using Assert.Equal due to case sensitiveness. | ||
| // So instead of using TestDirectory directly, we retrieve the real path with proper casing of the initial folder path. | ||
| private unsafe string GetTestDirectoryActualCasing() | ||
| { | ||
| try | ||
| { | ||
| using SafeFileHandle handle = Interop.Kernel32.CreateFile( | ||
| TestDirectory, | ||
| dwDesiredAccess: 0, | ||
| dwShareMode: FileShare.ReadWrite | FileShare.Delete, | ||
| dwCreationDisposition: FileMode.Open, | ||
| dwFlagsAndAttributes: | ||
| OPEN_EXISTING | | ||
| FILE_FLAG_BACKUP_SEMANTICS // Necessary to obtain a handle to a directory | ||
| ); | ||
|
|
||
| if (!handle.IsInvalid) | ||
| { | ||
| const int InitialBufferSize = 4096; | ||
| char[]? buffer = ArrayPool<char>.Shared.Rent(InitialBufferSize); | ||
| uint result = GetFinalPathNameByHandle(handle, buffer); | ||
|
|
||
| // Remove extended prefix | ||
| int skip = (result > 3 && buffer[0] == '\\' && buffer[3] == '\\' && (buffer[2] == '.' || buffer[2] == '?')) ? 4 : 0; | ||
adamsitnik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return new string( | ||
| buffer, | ||
| skip, | ||
| (int)result - skip); | ||
| } | ||
| } | ||
| catch { } | ||
|
|
||
| return TestDirectory; | ||
| } | ||
|
|
||
| private unsafe uint GetFinalPathNameByHandle(SafeFileHandle handle, char[] buffer) | ||
| { | ||
| fixed (char* bufPtr = buffer) | ||
| { | ||
| return Interop.Kernel32.GetFinalPathNameByHandle(handle, bufPtr, (uint)buffer.Length, Interop.Kernel32.FILE_NAME_NORMALIZED); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.