Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,17 @@ protected override void ProcessRecord()
}
catch (Win32Exception accessException)
{
WriteError(new ErrorRecord(accessException, "RemoveItemUnauthorizedAccessError", ErrorCategory.PermissionDenied, path));
// NativeErrorCode=2 - File not found.
// If the block stream not found the 'path' was not blocked and we successfully return.
if (accessException.NativeErrorCode != 2)
Copy link
Member

Choose a reason for hiding this comment

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

@jpsnover suggests adding a verbose message here if the block stream is not found

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. I tried to avoid adding a resource string

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to add a resource string saying:

File '{0}' did not contain a 'Zone.Identifier' file stream and was already not blocked.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a resouce string with {0} at last position - we should take into account long paths.

{
WriteError(new ErrorRecord(accessException, "RemoveItemUnauthorizedAccessError", ErrorCategory.PermissionDenied, path));
}
else
{
WriteVerbose(StringUtil.Format(UtilityCommonStrings.NoZoneIdentifierFileStream, path));
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@
<data name="TypeNotSupported" xml:space="preserve">
<value>'{0}' is not supported in this system.</value>
</data>
<data name="NoZoneIdentifierFileStream" xml:space="preserve">
<value>The file is not blocked: {0}</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Describe "Unblock-File" -Tags "CI" {
It "With '-Path': file exist" {
Unblock-File -Path $testfilepath
Test-UnblockFile | Should Be $true

# If a file is not blocked we silently return without an error.
{ Unblock-File -Path $testfilepath -ErrorAction Stop } | Should Not Throw
}

It "With '-LiteralPath': file exist" {
Expand All @@ -67,7 +70,6 @@ Describe "Unblock-File" -Tags "CI" {
$TestFileCreated = Get-ChildItem $TestFile
$TestFileCreated.IsReadOnly | Should Be $true

{ Unblock-File -LiteralPath $TestFile -ErrorAction SilentlyContinue } | Should Not Throw
$error[0].FullyQualifiedErrorId | Should Be "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.UnblockFileCommand"
{ Unblock-File -LiteralPath $TestFile -ErrorAction Stop } | ShouldBeErrorId "RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.UnblockFileCommand"
}
}