[darcs-users] DeleteFile on Windows

Petr Rockai me at mornfall.net
Tue Oct 27 09:12:59 UTC 2009

Petr Rockai <me at mornfall.net> writes:
> 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.


>From my reading of MSDN, it seems that you can never use DeleteFile on open
files. However, you can create a new handle using FILE_FLAG_DELETE_ON_CLOSE.

So my plan of action would be to make a removeFile replacement that (as
outlined in the above IRC discussion):
- rename the file to something unique (probably the original filename and an unique suffix)
- close the handle again

If the file was open with FILE_SHARE_DELETE previously, this should roughly
work. I haven't tested since it's difficult to work on win32 for me. Salvatore,
do you think this is something you could find time to do at the sprint in


More information about the darcs-users mailing list