Skip to content

FileSystemProvider.NameString uses realpath in Linux which resolves all links while Windows just returns the next target #15958

@jozkee

Description

@jozkee

Prerequisites

Steps to reproduce

Create 2 links and 1 file:

touch foo
ln -s bar foo
ln -s baz bar

so you have baz -> bar -> foo

I used the following Cmdlet to exemplify the error:

using System.Management.Automation;  // Windows PowerShell assembly.
using Microsoft.PowerShell.Commands;

namespace SendGreeting
{
  [Cmdlet(VerbsCommunications.Send, "Greeting")]
  public class SendGreetingCommand : Cmdlet
  {
    protected override void ProcessRecord()
    {
      WriteObject("Hello " + name + "!!");
      string fileName = FileSystemProvider.NameString(new PSObject(new System.IO.FileInfo("/home/user/baz")));
      WriteObject(fileName);
    }
  }
}
Import-Module /home/user/Cmdlet/bin/Debug/net5.0/Cmdlet.dll
Send-Greeting

Expected behavior

baz -> bar

Actual behavior

baz -> foo

Error details

This differs with Windows and also seems to differ when realpath fails since it fallsback to readlink:
https://github.com/PowerShell/PowerShell-Native/blob/deb01d6f65b07a0861933a2986cce2318fd60492/src/libpsl-native/src/followsymlink.cpp#L39-L54

Environment data

PS /home/jozky/pscore> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Linux 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerBreaking-Changebreaking change that may affect usersIssue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions