mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Resolve symbolic link target relative to the symbolic link instead of the working directory (#15235) (#20943)
This commit is contained in:
@@ -2258,16 +2258,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
exists = true;
|
||||
|
||||
var normalizedTargetPath = strTargetPath;
|
||||
if (strTargetPath.StartsWith(".\\", StringComparison.OrdinalIgnoreCase) ||
|
||||
strTargetPath.StartsWith("./", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
normalizedTargetPath = Path.Join(SessionState.Internal.CurrentLocation.ProviderPath, strTargetPath.AsSpan(2));
|
||||
}
|
||||
|
||||
GetFileSystemInfo(normalizedTargetPath, out isDirectory);
|
||||
|
||||
// unify directory separators to be consistent with the rest of PowerShell even on non-Windows platforms;
|
||||
// do this before resolving the target, otherwise e.g. `.\test` would break on Linux, since the combined
|
||||
// path below would be something like `/path/to/cwd/.\test`
|
||||
strTargetPath = strTargetPath.Replace(StringLiterals.AlternatePathSeparator, StringLiterals.DefaultPathSeparator);
|
||||
|
||||
// check if the target is a file or directory
|
||||
var normalizedTargetPath = Path.Combine(Path.GetDirectoryName(path), strTargetPath);
|
||||
GetFileSystemInfo(normalizedTargetPath, out isDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user