Skip to content

Conversation

@powercode
Copy link
Collaborator

@powercode powercode commented Oct 14, 2018

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
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
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
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 iSazonov self-assigned this Oct 23, 2018
@iSazonov iSazonov merged commit 3e4fa87 into PowerShell:master Oct 24, 2018
Copy link
Member

@TravisEz13 TravisEz13 left a comment

Choose a reason for hiding this comment

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

LGTM

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