0

So the question may look strange. I've encountered many times a folder that cannot be deleted on a NTFS filesystem unless the PC was rebooted. When this happens, the issue is not a permission things, even the local administrator can't deal with it. But reboot the PC and the folder is gone.

Even this Microsoft post says that it is a possible behaviour

Now, I have an application that creates a temporary folder, write inside it and deletes it afterward. Sometime, this application crashes because it cannot delete the files inside that folder. When I look at it, the temporary folder is empty and show the behaviour described above.

So my question goes as follow : How can my software do that? I would like to debug this but I have no clue where to start as I would expect the filesystem to be robust when accessed through the WinAPI. My application is a C# .Net 4.5 application.

Is there known vulnerabilities on the NTFS filesystems that could result in bad sectors? We're talking about Windows 7. This looks a lot like a race condition scenario.

Thanks!

  • Can you confirm it's not locked: https://stackoverflow.com/a/11060322/495455 or you could use a tool called Unlocker. The most likely reason is permissions. An admin can't delete a file/folder if someone else has a lock on it. – Jeremy Thompson Jul 11 '18 at 02:43
  • hmmm, no I can't confirm now. That may be a good potential solution. I will check – Pier-Yves Lessard Jul 11 '18 at 02:47
  • What error do you get when the code "crashes"? – JohnG Jul 11 '18 at 03:00
  • I get a "System.UnauthorizedAccessException - Access to path is denied". Then I look at my temp folder, it's empty, but I cannot delete the folder. – Pier-Yves Lessard Jul 11 '18 at 03:02
  • If I am dealing with a locked file scenario, how come the temporary folder is being deleted after a reboot? Can the OS queue the delete operation? My windows under-the-hood knowledges isn't so good. – Pier-Yves Lessard Jul 11 '18 at 03:05
  • Can you post the code that deletes the file? – JohnG Jul 11 '18 at 03:07
  • I can surely provide a simplified version of it tomorrow. – Pier-Yves Lessard Jul 11 '18 at 03:09
  • 1
    Some buggy antivirus software will keep a file locked after the application is done using it. (The bug isn't because it opens the file -- AV has to do that -- but because it doesn't respond to the delete request by releasing all handles and approving the request) – Ben Voigt Jul 11 '18 at 03:26
  • Go and have a look at what processes have the file open [process-explorer](https://learn.microsoft.com/en-gb/sysinternals/downloads/process-explorer) if its you, then you have learned a very good lesson, if its your AV then you have learnt another – TheGeneral Jul 11 '18 at 04:50
  • Maybe the failing app opened a file with FILE_FLAG_DELETE_ON_CLOSE and crashed with the file open? – Clay Jul 18 '18 at 19:41

0 Answers0