Skip to content

New-Item -ItemType SymbolicLink cannot understand directory path ending with slash on Linux - #2974

Merged
Mike Richmond (mirichmo) merged 1 commit into
PowerShell:masterfrom
chunqingchen:bugfix1
Apr 18, 2017
Merged

Mike Richmond (mirichmo) merged 1 commit into
PowerShell:masterfrom
chunqingchen:bugfix1

Conversation

@chunqingchen

@chunqingchen Chunqing Chen (chunqingchen) commented Jan 7, 2017 •

Copy link
Copy Markdown
Contributor

Relevant issue: #2865

Steps to reproduce

New-Item -ItemType SymbolicLink -Path /foo/ -Value /bar/

Expected behavior

Symbolic link is created from /foo/ to /bar/.

Actual behavior

New-Item : No such file or directory

Removing the slash at the end of the Path argument makes the call behave as expected. This is counterintuitive, as a slash at the end of a path generally works fine in PowerShell scripts to designate directories (and directory links).

Environment data

Running PowerShell on Ubuntu 16.04.

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.12
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

@mirichmo Mike Richmond (mirichmo) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please include tests for this change

@mirichmo

Copy link
Copy Markdown
Member

Chunqing Chen (@chunqingchen) Ping

@chunqingchen

Copy link
Copy Markdown
Contributor Author

Mike Richmond (@mirichmo) the tests are added.

@mirichmo

Copy link
Copy Markdown
Member

Chunqing Chen (@chunqingchen) Thank you. Please assign appropriate reviewer(s) to review this change

@chunqingchen

Copy link
Copy Markdown
Contributor Author

Francisco Gamino (@Francisco-Gamino) hi Francisco, it seems you have reviewed the code file recently. Would you mind help me review this change? Thank you~

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should probably be:

Get-Item "$tmpDirectory/$folderName/" -ErrorAction SilentlyContinue | remove-item -force -recurse -ErrorAction SilentlyContinue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately remove-item would not work here because the item is a symboliclink path. It will lead to a System.ComponentModel.Win32Exception.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if these are all created in $TESTDRIVE, there's no clean up needed at all, as pester will take care of it
Also, please fix spelling error Directoy => Directory


In reply to: 110466085 [](ancestors = 110466085)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Chunqing Chen (@chunqingchen): Good to know. Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we specified in the comment that Path.AltDirectorySeparatorChar referred to ('') on UNIX and a slash ('/') on Windows and Mac?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

resolvePath [](start = 20, length = 11)

I'm not sure that this can be so simple, are we guaranteed that the order will be this? For example, will we'll always get "", and then "/"?

@chunqingchen

Copy link
Copy Markdown
Contributor Author

Francisco Gamino (@Francisco-Gamino) Thanks Francisco for the review, the comments are resolved.

@chunqingchen

Copy link
Copy Markdown
Contributor Author

James Truher (@JamesWTruher) Thanks Jim for the review, the comment has been resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You have an extra space before ' '
char[] charsToTrim = {<extra_pace>' '...

@Francisco-Gamino

Copy link
Copy Markdown
Contributor

Chunqing Chen (@chunqingchen): Just one minor comment. Other than that, it LGTM.

@chunqingchen

Copy link
Copy Markdown
Contributor Author

Francisco Gamino (@Francisco-Gamino) the space is removed. thanks !

@chunqingchen

Copy link
Copy Markdown
Contributor Author

Mike Richmond (@mirichmo) can you merge now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Directoy --> Directory

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants