Skip to content

Add a path for checking ZoneInformation without throwing an exception - #8025

Merged
Ilya (iSazonov) merged 5 commits into
PowerShell:masterfrom
powercode:Perf/ZoneInfoException
Oct 24, 2018
Merged

Ilya (iSazonov) merged 5 commits into
PowerShell:masterfrom
powercode:Perf/ZoneInfoException

Conversation

@powercode

@powercode Staffan Gustafsson (powercode) commented Oct 14, 2018 •

Copy link
Copy Markdown
Collaborator

PR Summary

In an effort to reduce the number of exceptions we throw as standard flowcontrol, this PR adds

bool TryCreateFileStream(
    string path,
    string streamName, 
    FileMode mode, 
    FileAccess access, 
    FileShare share,  
   out FileStream stream) 

as a non-throwing alternative to CreateFileStream.

This makes the code slightly faster and debugging slightly less annoying.

PR Checklist

string errorMessage = StringUtil.Format(
FileSystemProviderStrings.AlternateDataStreamNotFound, streamName, path);
throw new FileNotFoundException(errorMessage, resultPath);
throw new FileNotFoundException(errorMessage, $"{path}:{streamName.Trim()}");

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.

Do we really need Trim() for streamName in the internal methods? We do not this for path.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure - I just opted to not change any functionality. Small cost on the error path.

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.

I vote to remove - I believe consumer should take care.

@iSazonov
Ilya (iSazonov) merged commit 3e4fa87 into PowerShell:master Oct 24, 2018

@TravisEz13 Travis Plunk (TravisEz13) 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.

LGTM

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.

4 participants