Under some circumstances, the rm
command in Git-Bash deletes files that can't be deleted in explorer, cmd prompt, PowerShell, or using C++ standard library calls.
Why?
This is perplexing to me because I know there is no magic here and I assume that they are all using the same Win32 API.
For example, I have database snapshots that remain open and cannot be deleted using the other methods described, but are successfully deleted by Git-Bash rm
:
Explorer delete: "The action cannot be completed because the file is open."
cmd: del <path>
: "Access is denied"
PS: Remove-Item -Force -Path <path>
: "Cannot remove item. Access to the path is denied."
C++ remove()
: returns -1
C++ unlink()
: returns -1
C++ _unlink()
: returns -1
git-bash rm <path>
: success
The above can be performed repeatedly on different files.
There are other locked files that git-bash rm
deletes successfully as well (I have used it in the past, not recently and I don't have other specific examples).
However it doesn't always work: In a test application I opened a text file using fopen()
and none of the methods, including Git-Bash rm
, could successfully delete it.
So, how does Git-Bash rm work?