GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Fix Rename-Item -Path with wildcard char by kwkam · Pull Request #7398 · PowerShell/PowerShell Conversation
|
| /// </summary> | ||
| protected override void ProcessRecord() | ||
| { | ||
| do |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why do we use cycle here? We have single input string.
I would try to make things easier - just try to rename in try-catch.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| <value>Cannot move item because the item at '{0}' is in use.</value> | ||
| </data> | ||
| <data name="RenameMultipleItemError" xml:space="preserve"> | ||
| <value>Cannot rename item because the path '{0}' resolved to multiple items. Only one item can be renamed at a time.</value> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It makes no sense to tell the user that we have tried to resolve wildcards - in fact, we consider the Path parameter as literal.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we would add support for renaming multiple items like the ren command in cmd?
eg. Rename-Item -Path '*.txt' -NewExtension '.bak'
or, Rename-Item -Path '*.txt' -Format 'renamed_{0}'
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I believe the enhancement is out of the PR and we should discuss it in a new tracking Issue (please open).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| } | ||
| finally { | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can remove the empty finally block.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| protected override void ProcessRecord() | ||
| { | ||
| try | ||
| { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Seem all used methods use try-catch and we can remove the try.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This reverts commit be59b3d.
|
kwkam Please rebase to fix CI Travis failure. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please look tests - I don't see test related the PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| private Collection<PathInfo> GetResolvedPaths(string path) | ||
| { | ||
| Collection<PathInfo> results = new Collection<PathInfo>(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It is extra allocation. I think we should remove this and check null in calling code.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Updated test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| break; | ||
|
|
||
| default: | ||
| RenameItem(Path, literalPath: true); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is this really working?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'd expect that we unescape path, check existance (or try rename), if fail then resolve globs (write an error if cpunt > 1) and try rename again.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I believe -Path should try to resolve globs first, since it's the expected behaviour, and users can escape the wildcard character, for example
Rename-Item -Path '`[A-B`]' -NewName 'A-B'
will prevent globbing.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// </summary> | ||
| protected override void ProcessRecord() | ||
| { | ||
| if (base.SuppressWildcardExpansion) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do we really need base prefix?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ilya (@iSazonov) Should I run |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Why do you need to rebase? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
kwkam Ok, I understand. You can rebase to temporary skip broken tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ilya (@iSazonov) I see. I would not rebase if it is not necessary. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Do not escape CWD when LiteralPath is used. This causes issues when both -LiteralPath and CWD contains special characters.
|
This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Steve Lee (@SteveL-MSFT) do we have interest in the change? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ilya (@iSazonov) yes, interested in this change |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
kwkam Please rebase to pass CIs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ilya (@iSazonov) OK, rebased to latest master. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
kwkam Thank you for your contribution! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.