[darcs-users] DeleteFile on Windows

Petr Rockai me at mornfall.net
Sat Oct 10 08:26:59 UTC 2009


Hi,

Simon Marlow <marlowsd at gmail.com> writes:
> Yes, using FILE_SHARE_DELETE sounds like a good plan.  Be careful though:
>
> http://blogs.msdn.com/oldnewthing/archive/2004/06/07/150047.aspx
>
> if you delete the file, even though the DeleteFile succeeds, it still exists in
> the directory until the last HANDLE is closed.  So an attempt to create a file
> with the same name will still fail.  If you are deleting a file in order to
> create a new one with the same name, then you better call MoveFile() before
> DeleteFile().
That'd be great news. So basically, there are two bits we need to address:

- for _darcs/index, we need to first rename it to a suitable name and then delete
- we need to memory-map everything with FILE_SHARE_DELETE

The catch is, that we already do the latter and it doesn't really seem to help?
The exact C code is this (from cbits/win32.c from the mmap-0.4 package):

    38     handle = CreateFileA(filepath,
    39                          dwDesiredAccess,
    40                          FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    41                          NULL,
    42                          dwCreationDisposition,
    43                          FILE_ATTRIBUTE_NORMAL,
    44                          NULL);

Maybe I just misunderstand how this is used? Any hints would be appreciated.

Yours,
   Petr.


More information about the darcs-users mailing list