Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Jul 18, 2022

PR Summary

If you run this command:

get-childitem -path c:\foo\bar -recurse

and the subfolder bar does not exist and a subfolder called b doesn't exist, you get an incorrect error message:

Get-ChildItem: Cannot find path 'C:\foo\b' because it does not exist.

The problem is that the code is trying to find the parent of bar, which should be C:\foo\ but because of the trailing slash, it has an off-by-one error resulting in c:\foo\b. It then tries to find this folder which results in the error message. If by chance a folder b exists, then Get-ChildItem would traverse into that folder and return incorrect results.

The fix here is if the path ends in a trailing slash, then we treat the last part as indicating a directory and never a folder. So we add checks for that and if "c:\foo\bar" where a folder "bar" doesn't exist, you'll get the right error message with the path.

However, part of the fix works around an issue with .NET FileInfo::new() which happily accepts a path to a file with a trailing slash and returns an incomplete object. Since this repros with .NET Framework, it seems unlikely to be changed (Get-Item demonstrates the behavior and is not changed in this PR) so I added code to fail if such an object is returned.

PR Context

This issue was brought up in this thread: https://twitter.com/SBarizien/status/1549000209610510336

PR Checklist

@pull-request-quantifier-deprecated

This PR has 11 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +10 -1
Percentile : 4.4%

Total files changed: 3

Change summary by file extension:
.cs : +3 -1
.ps1 : +7 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@ghost ghost assigned iSazonov Jul 18, 2022
@iSazonov
Copy link
Collaborator

@SteveL-MSFT Please update the PR summary - the description confuses rather than adds to the understanding.

Co-authored-by: Paul Higinbotham <paulhi@microsoft.com>
@SteveL-MSFT
Copy link
Member Author

@iSazonov just to be clear, is the first part which is more about the issue than the fix the confusing part? I can just remove that. Or is it the second part trying to explain the root cause and the change?

@iSazonov
Copy link
Collaborator

@iSazonov just to be clear, is the first part which is more about the issue than the fix the confusing part?

  1. We should remove 1376 and 1378
  2. Cleanup FileSystem provider #6909 was mentioned only for better understanding the issue comes from.

I can just remove that. Or is it the second part trying to explain the root cause and the change?

As for my second comment, I did not investigate why my example doesn't work but before we merge the PR I'd want to understand whether it is that issue or another issue. Could you please confirm the PR fix it too?

@SteveL-MSFT
Copy link
Member Author

@iSazonov ok, now I understand what you are saying. I'll remove those two lines as they aren't correct. I'll investigate your use case to understand what is happening.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jul 21, 2022
@iSazonov iSazonov merged commit 3efa281 into PowerShell:master Jul 21, 2022
@SteveL-MSFT SteveL-MSFT deleted the gci-recurse-trailingslash branch July 22, 2022 04:51
@ghost
Copy link

ghost commented Aug 12, 2022

🎉v7.3.0-preview.7 has been released which incorporates this pull request.:tada:

Handy links:

@TravisEz13 TravisEz13 mentioned this pull request Sep 30, 2022
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Extra Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants