Repository navigation
dir -hidden -force c:\pagefile.sys returns an error (#2144) - #2273
Conversation
|
Hi Charu Bassi (@charub), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
a46453a to
f489d60
Compare
There was a problem hiding this comment.
fwiw, this should be "Fall back" (verb+adverb ~ verb phrase) instead of "Fallback" (noun)
There was a problem hiding this comment.
You can (and probably should) omit "or not"
Josh Soref (jsoref)
left a comment
There was a problem hiding this comment.
As a user who has hit this rather annoying error, thanks for fixing it!
Sorry for the drive by grammatical notes. Hopefully, they're vaguely helpful to some readers. (I feel somewhat invested in this, as I've sent quite a few PRs and changes to improve the readability of PowerShell's source code.)
There was a problem hiding this comment.
Maybe this if ... else ... block can be changed to
isDirectory = (findData.dwFileAttributes & NativeMethods.FileAttributes.Directory) != 0;
There was a problem hiding this comment.
Gud one! Made the change.
There was a problem hiding this comment.
Maybe it's not necessary to call NativeMethods.FindClose when findHandle is invalid. And NativeMethods.FindClose should be placed in a finally block in case of any unexpected exception.
There was a problem hiding this comment.
Although FindClose() internally takes care if the handle is invalid. But in our case , we are anyways checking if the handle is valid, so calling FindClose() only in case it's valid.
There was a problem hiding this comment.
IntPtr findHandle;
findHandle = NativeMethods.FindFirstFile(path, out findData);
This should be put in one line: IntPtr findHandle = NativeMethods.FindFirstFile(path, out findData);
There was a problem hiding this comment.
can FindFirstFile get the handle of a file even if the file is being use by another process? If so, can you please add some comments explain your research on that?
There was a problem hiding this comment.
Made the change suggested in the comment
There was a problem hiding this comment.
GetFileAttributes can get the handle to a file even if it is shared by another process but it fails when the sharing flag for the file is set to 0x00000000. This happen because GetFileAttributes function tries to open the file with FILE_READ_ATTRIBUTES access right. It prevents us from opening a file for delete, read, or write access. In current scenario, C:\pagefile.sys is always opened by OS with sharing flag 0x00000000. But FindFirstFile is still able to get attributes as this api retrieves the required information using a find handle generated with FILE_LIST_DIRECTORY access.
There was a problem hiding this comment.
Nice. Please add this to the code as comments.
There was a problem hiding this comment.
nitpick: the order probably should be if (errorCode == 5) ... else if (32) ... else if (53) ...
There was a problem hiding this comment.
And another one -- not related to this fix -- it seems for any other error code we just silently sallow it without throw error. Probably it was by design. It might be a breaking change to fix that.
There was a problem hiding this comment.
Similar comments here as above.
There was a problem hiding this comment.
Remove-Item should be in a finally block or in AfterEach block, so that it will be cleaned up even if any Should Be above failed.
There was a problem hiding this comment.
There's no need to remove TestDrive. Pester internally takes care of that. So, removing this statement.
There was a problem hiding this comment.
Maybe add > $null to New-Item.
There was a problem hiding this comment.
These 4 statements seems redundant for each test. Maybe you should put them in a BeforeAll or BeforeEach block.
There was a problem hiding this comment.
Moved to BeforeAll block for this context.
There was a problem hiding this comment.
Removed!
There was a problem hiding this comment.
($IsLinux -Or $IsOSX )
Maybe just (! $IsWindows)
There was a problem hiding this comment.
what if the system drive is not C:?
There was a problem hiding this comment.
using $env:SystemDrive instead of hard coded c:\
39b76ca to
0227b3a
Compare
Dongbo Wang (daxian-dbw)
left a comment
There was a problem hiding this comment.
It's recommended to use more descriptive commit message other than the issue title. In this case, maybe we can use:
"Fix Get-ChildItem -Hidden to work on system hidden files like c:\hiberfil.sys c:\pagefile.sys and c:\swapfile.sys"
0227b3a to
b7fbdc4
Compare
Resolving #2144