8000 Fix unblock read only file by iSazonov · Pull Request #4395 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fix unblock read only file #4395

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

Merged
merged 4 commits into from
Aug 14, 2017
Merged

Conversation

iSazonov
Copy link
Collaborator
@iSazonov iSazonov commented Jul 31, 2017

Adds a new non-terminating error

Fix #4390.

Problem

If a file is read only it is skipping silently.

Fix

Analize GetLastError() and throw if a file stream hasn't been removed.

First commit only refactor tests to use ShouldBeErrorId.

@SteveL-MSFT
Copy link
Member

@iSazonov what is the error message the user sees now?

@iSazonov
Copy link
Collaborator Author
iSazonov commented Aug 2, 2017

MSDN says that GetLastError can return either "Access denied" or "File not found".

Unblock-File : Access is denied
At line:1 char:1
+ Unblock-File -Path $Testpath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Unblock-File], Win32Exception
    + FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.UnblockFileCommand

SteveL-MSFT
SteveL-MSFT previously approved these changes Aug 2, 2017
Copy link
Member
@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

if (!NativeMethods.DeleteFile(resultPath))
{
int error = Marshal.GetLastWin32Error();
throw new Win32Exception(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be a non-terminating error? The following should behave similarly:

dir | Unblock-File
dir | Remove-Item

In the Remove-Item case, a read only file reports an error, but all other files are deleted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch!
AlternateDataStreamUtilities uses the pattern. So maybe add try-catch in Unblock-File cmdlet file?

@TravisEz13 TravisEz13 self-assigned this Aug 5, 2017
@iSazonov
Copy link
Collaborator Author

@lzybkr @SteveL-MSFT Please continue the code review.

@TravisEz13 TravisEz13 dismissed SteveL-MSFT’s stale review August 11, 2017 17:27

A commit has been added to the review

Copy link
Contributor
@lzybkr lzybkr left a comment

Choose a reason for hiding this comment

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

Make sure the final commit message points out this is a new non-terminating error.

@TravisEz13 TravisEz13 merged commit 813e4a6 into PowerShell:master Aug 14, 2017
@iSazonov iSazonov deleted the fix-unblock-file-ro branch August 15, 2017 09:22
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.

5 participants
0