Skip to content

New-Item Type SymbolicLink on Unix-like platforms unexpectedly converts relative target paths to absolute one #15233

Closed

Description

PR #12797 tried to implement support for relative target paths for symbolic links (symlinks).

  • On Windows, this now works properly.

  • On Unix-like platforms, a relative input path is still unexpectedly converted to a full path and stored as such in the symlink.

Steps to reproduce

Note: Run on macOS and/or Linux (the test succeeds on Windows).

Push-Location -ea Stop ($tmpDir = (New-Item -Type Directory -Force (Join-Path Temp:/ $PID)).FullName)

# Create a file to serve as the symlink target.
$null = New-Item -Force file

# Determine the native file-system path separator, as well as the one 
# *not* native to the platform.
$sep = [IO.Path]::DirectorySeparatorChar
$otherSep = $sep -eq '/' ? '\' : '/'

# To also test path-separator normalization, we use the non-native separator.
$null = New-Item -Force -Type SymbolicLink fileL -Target ".${otherSep}file"

# The symlink's target should be a relative path that uses the platform-appropriate path separator.
(Get-Item fileL).Target | Should -Be ".${sep}file"

# Clean up.
Pop-Location; Remove-Item $tmpDir -Recurse

Expected behavior

The test should succeed.

Actual behavior

The test fails, because the relative input path is unexpectedly first resolved to a full path before the symlink is defined:

InvalidResult: Expected strings to be the same, but they were different. 
Expected length: 6 Actual length:   14 Strings differ at index 0. 
Expected: './file' But was: '/tmp/2802/file'

Environment data

PowerShell Core 7.2.0-preview.4

Activity

  1. added
    Needs-Triage
    on Apr 14, 2021
  2. added
    WG-Engine-Providers
    Issue-Bug
    on Apr 15, 2021
  3. added this to the 7.2-Consider milestone on Apr 15, 2021
  4. removed
    Needs-Triage
    on Jun 9, 2021
  5. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. added
    Resolution-No Activity
    on Nov 16, 2023
  9. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-ProviderIssue-BugResolution-No ActivityWG-CmdletsWG-Engine-Providers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions