Delete directories opened with FILE_SHARE_DELETE

The behaviour described in the bug report is either by design, or would be far too complex/time-consuming to be changed

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
SUKER
Junior Member
Junior Member
Posts: 88
Joined: 2003-08-25, 07:15 UTC

Delete directories opened with FILE_SHARE_DELETE

Post by *SUKER »

Hi. Current TC behavior of directly deleting directories (files?) opened by other programs with FILE_SHARE_DELETE flag is a bit user confusing - TC can't delete them :( After shift+del, if we try simple del on this dir, we will get an error could not find this item and dir will disappear:
Spoiler
For now with such directories:
  • Explorer delete them without a problem to recycle bin or directly.
  • TC with explorer delete method, delete them without a problem to recycle bin or directly - that obviously.
  • TC with default method, delete them without a problem to recycle bin.
  • TC with default method, can't delete them directly.


Tested on windows 7 x64, Tc ? - 9.22a, 9.50RC1 (x64/x86 with VistaDelete=1/0).
For developer that uses git + TortoiseGit + TC it's a nightmare to directly delete repositories from TC, due to TGitCache.exe process open all repos folders with FILE_SHARE_DELETE...

Just in case, the video of the problem.

I understand that RemoveDirectory can't delete such folders (leave them until handle is released). But, can we use a mixed delete method for such things? Use shell (IFileOperation) methods after or instead RemoveDirectory for such dirs?
Thanks.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Delete directories opened with FILE_SHARE_DELETE

Post by *ghisler(Author) »

Sorry, I don't have any plans to change this. My guess is that the directory is the current directory in some program, which also prevents it from being deleted. Deleting to recycle bin will not fail because the directory is moved to recycle bin (and renamed in the process), not really deleted.
Author of Total Commander
https://www.ghisler.com
User avatar
SUKER
Junior Member
Junior Member
Posts: 88
Joined: 2003-08-25, 07:15 UTC

Re: Delete directories opened with FILE_SHARE_DELETE

Post by *SUKER »

ghisler(Author) wrote: 2020-01-27, 11:24 UTC My guess is that the directory is the current directory in some program, which also prevents it from being deleted.
It's not the case in this situation, it's can be simple proved. In my video above, i searched and then show the only open handle. And it's opened with FILE_SHARE_DELETE for a reason...
ghisler(Author) wrote: 2020-01-27, 11:24 UTC Deleting to recycle bin will not fail because the directory is moved to recycle bin (and renamed in the process), not really deleted.
Yes, but explorer (shell / IFileOperation methods ) can delete this bypassing recycle bin (what was mentioned above).
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Delete directories opened with FILE_SHARE_DELETE

Post by *ghisler(Author) »

How should IFileOperation, a high level function, be able to delete a folder which a low level function cannot delete? This just doesn't make any sense at all.
Author of Total Commander
https://www.ghisler.com
User avatar
SUKER
Junior Member
Junior Member
Posts: 88
Joined: 2003-08-25, 07:15 UTC

Re: Delete directories opened with FILE_SHARE_DELETE

Post by *SUKER »

ghisler(Author) wrote: 2020-01-28, 07:36 UTC How should IFileOperation, a high level function, be able to delete a folder which a low level function cannot delete? This just doesn't make any sense at all.
My bad :( I thought that explorer delete method in TC uses shell functions.
I looked at TortoiseGit code and found that after opening dirs with FILE_SHARE_DELETE, they watched for them, and if some one delete them, they free handles... Interesting thing, that they can't catch TC deletes :) I wrote a simple program that delete dirs with RemoveDirectory or SHFileOperation. They catch both of this methods + they catch explorer method, they can't catch only TC direct deletes :) But of course this is another problem...
Thank you!
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Delete directories opened with FILE_SHARE_DELETE

Post by *ghisler(Author) »

Very strange - are you perhaps running TC with higher user rights?
Author of Total Commander
https://www.ghisler.com
User avatar
SUKER
Junior Member
Junior Member
Posts: 88
Joined: 2003-08-25, 07:15 UTC

Re: Delete directories opened with FILE_SHARE_DELETE

Post by *SUKER »

ghisler(Author) wrote: 2020-01-28, 16:35 UTC Very strange - are you perhaps running TC with higher user rights?
No, all programs run from same user. I recorded a video (deletion same dir bypassing recycle bin with TC and SHFileOperation from test program) where this all seen.
I understand, that this is not a priority problem at all, but interesting :) So, may be in the future, if you will have a free time and interest? ...
Post Reply