-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Remove alternate file stream code from non-Windows #4567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unblock-File is excluded from Unix at all so we don't need to exclude the code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That file is still being compiled on Unix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should exclude them in csproj.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with that but then we have effectively conditional compilation in both the source and the csproj files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a check that ${testPath}:Stream is a file name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't Get-Content implicitly cover that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if the Content cmdlets were doing something funny it could mask an issue, I'll add a check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary change of line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change of grouping of the variables makes it a bit more readable to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this block be surrounded by #if !UNIX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of this code is unnecessary on UNIX so I'll wrap it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Test-Path instead of Test_path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, odd that this test passed
0191663 to
8c69d06
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add #if !UNIX to the start of the file like: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/utils/tracing/EtwActivity.cs#L1
That seems more discoverable to me when doing code reviews or debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I had originally. Did a search and I don't see other cases of conditional compilation, so I think it's more consistent to use a whole file #ifdef. @iSazonov ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's technically better to exclude files in csproj files. But currently we don't use a lot of opportunities of MSBuild and also we are cleaning up FullCLR files and respectively remove "Compile Remove" from csproj files. So it is Ok to use #ifdef .
/cc @daxian-dbw Could you comment too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really have a preference although csproj approach seems more discoverable. However in this case, I don't think Unblockfile.cs should be completely excluded from Unix build as it will increase the number of #if unix/endif blocks in places where the code from this file is used, which will impact readability.
8c69d06 to
7209973
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This #if/#endif block is cumbersome to read. Suggest instead:
if (result != null)
{
#if UNIX
WriteItemObject(...)
#else
original code
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WriteItemObject code applies to both UNIX and !UNIX. If I move that bit of code up, I'd need more #ifdefs making it less readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, if you don't mind duplicating the WriteItemObject line, it can be a pure #if #else block. Your call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the other case I was fine with a bit of duplication, but prefer to leave this one as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, the code is easier to read if you use a #if UNIX and contain the UNIX lines completely. Its a simple if/else with a single statement for UNIX but looks unwieldy with the current #if/#else placement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move some code around so the UNIX code is in one place and the !UNIX code is also together.
Should this also be conditioned on !UNIX? Refers to: src/System.Management.Automation/namespaces/FileSystemProvider.cs:4270 in 7209973. [](commit_id = 720997351e1de1cf26593cfe0e95699d8b3b9eb3, deletion_comment = False) |
Shouldn't there be a Platform.IsSameFileSystemItem? Refers to: src/System.Management.Automation/namespaces/FileSystemProvider.cs:8274 in 7209973. [](commit_id = 720997351e1de1cf26593cfe0e95699d8b3b9eb3, deletion_comment = False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On UNIX, _stream will be null causing a ArgumentNullException from new StreamReader at line 874. At best, it will be misleading. Consider throwing NotSupportException on UNIX in the associated constructors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, will change
|
@dantraMSFT I addressed your feedback. Regarding |
22cc78b to
f0260d7
Compare
|
I believe all feedback has been addressed |
PaulHigin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR has been updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be in the #if !UNIX block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable won't be used on Unix and should be moved to the #if !UNIX block below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternate streams can be specified using -Stream or an inline stream syntax "file::stream", the check of the inline stream syntax is done in 7 places in FileSystemProvider.cs but some of them are not within #if !UNIX block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And when running Get-Content -Path file::stream on Linux, it probably should throw an error message about "alternate stream is not supported" instead of working unexpectedly or fail with other errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Unix, a colon is completely allowed in a filename, so we want that to continue working as just a filename. Tests were added to make sure this works.
I'll fix other cases of using the file:stream syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it more and now have this question: which the following experience is better -- copy Get-Content -Path <file> -Stream <stream> to Linux powershell and see the error "A parameter cannot be found", or "Alternate stream is not supported on this platform"? I think the latter message is better. To achieve this, maybe we can make the setter of the Stream property throw PlatformNotSupportedException on non-windows.
As for #if UNIX/endif blocks, IMHO, we don't necessarily need to have all codes that only apply to a specific platform guarded by the compile definition. I think it's OK to keep such codes around even for other platforms, and the guideline should be readability and maintainability. I still feel it's better to avoid most of the #if UNIX blocks by controlling the entry points:
- Make sure
-Streamnot available on Unix platforms - Throw error when the inline stream syntax is used for
-Pathon Unix platforms - Skip the alternate stream discovery codes during remote copy (both
PerformCopyFileFromRemoteSessionandPerformCopyFileToRemoteSession) on Unix platforms.
After controlling those entry points (and put some comments for sure), it's safe to know that the alternate stream related code paths will not be hit on Unix platforms.
TravisEz13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please work on correctly resolving merge/rebase issue.
assets/Product.wxs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something isn't correct in your PR. Already committed changes are in the diff.
|
It looks like the email on your latest commit is not associated with your github account. |
…work on non-Windows and produces errors about not loading a dll in the case of copy-item
added new -stream tests
8e6aa4e to
7701b7a
Compare
|
@TravisEz13 fixed |
|
@TravisEz13 @daxian-dbw feedback addressed |
Comment is addressed by new commits.
AlternateStreams support relies on pinvoke to win32 apis which don't work
on non-Windows and produces errors about not loading a dll in the case of copy-item
Fix #4542