[RFC] unlink() implementation

Corinna Vinschen vinschen@redhat.com
Fri Oct 10 20:18:00 GMT 2003


the discussion in the Cygwin ML about removing files led Chris and me
to some more discussing the implementation of unlink() and some more
tests.  Basically, the description in MSDN about DeleteFile is wrong.
MSDN claims

  "In the Windows 95 and 98 environment, the DeleteFile function
   deletes a file even if it is open unless the file has been opened
   with the FILE_SHARE_DELETE flag."

First, a file which is open in the same or another process can not
be deleted.  Second, adding the FILE_SHARE_DELETE flag to CreateFile
calls results in a failing CreateFile.  This, OTOH, matches the
MSDN description of CreateFile:

  "FILE_SHARE_DELETE [...] Windows 95/98/Me: This flag is not supported."

Third, even FILE_FLAG_DELETE_ON_CLOSE has no effect on 9x, even though
MSDN does not mention any problem with that flag on 9x/Me.

So, while the implementation of unlink() works fine on NT systems
(we seem to have even more working code than necessary) the implementation
looks a bit cheerless on 9x/Me in terms of POSIX-like behaviour:

  DeleteFile?  Works if the file isn't open, otherwise it fails.
  If it fails, the file is stored in the delqueue.  This results
  in the file being deleted on exit... if the file hasn't been opened
  by another process.

The delqueue is (to say it with cgf) a horrible kludge which we're
trying to avoid as far as possible.

So, I would like to ask you folks, what you think about the idea,
to try to move the file into the recycle bin, if delete file fails.
The whole implementation then looks like this, every step only tried
if the step before failed:

Step 1 (Only on NT):

    Try CreateFile(FILE_FLAG_DELETE_ON_CLOSE)/CloseHandle();

Step 2:

    Try DeleteFile();

Step 3:

    Try SHFileOperation(FO_DELETE)  // moves to Recycle Bin

Step 4:

    Store in delqueue.

Besides the examination, that we could drop step 1 on NT, what do
people think about the idea, to try to move the file to the
recycle bin if a DeleteFile failed?  Note that I didn't actually
*test* it, but I'd like to know, if I'm something missing which
invalidates the idea.  Any really bad caveat?


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

More information about the Cygwin-developers mailing list