Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix unblock read only file#4395

Merged
TravisEz13 merged 4 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:fix-unblock-file-roiSazonov/PowerShell:fix-unblock-file-roCopy head branch name to clipboard
Aug 14, 2017
Merged

Fix unblock read only file#4395
TravisEz13 merged 4 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:fix-unblock-file-roiSazonov/PowerShell:fix-unblock-file-roCopy head branch name to clipboard

Conversation

@iSazonov

@iSazonov iSazonov commented Jul 31, 2017

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Member

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

@iSazonov

iSazonov commented Aug 2, 2017

Copy link
Copy Markdown
Collaborator Author

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

@SteveL-MSFT SteveL-MSFT 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

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@lzybkr lzybkr left a comment

Copy link
Copy Markdown
Contributor

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.