make-w32
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Switching from CVS to GIT


From: Eli Zaretskii
Subject: Re: Switching from CVS to GIT
Date: Mon, 15 Oct 2007 08:53:38 -0400

> Date: Mon, 15 Oct 2007 07:58:43 -0400
> From: Earnie Boyd <address@hidden>
> 
> 
> Quoting Eli Zaretskii <address@hidden>:
> 
> >> Date: Mon, 15 Oct 2007 00:45:47 +0100 (BST)
> >> From: Johannes Schindelin <address@hidden>
> >> cc: Alex Riesen <address@hidden>, address@hidden, address@hidden,
> >>     address@hidden, address@hidden
> >>
> >> The problem is that on Windows, you cannot keep a file open and delete it
> >> at the same time.
> >
> > That is no longer true, for quite some time.  NT4 and later versions
> > support that almost exactly like Posix filesystems.
> >
> 
> You still can't keep a file open and delete it as far as I know.  If 
> you can please share how.

I attach a short toy program that can demonstrate this.  While it
sleeps for 30 seconds, go to another shell window and delete the file
which it has open (either its first command-line arg or "topen.tst" if
no arg was given.  Then try `dir' or `ls' on the removed file, and you
will see that continues to be listed until the program closes the
handle, at which point it is actually removed.

Again, this is a toy program, so please don't pounce on me saying that
it doesn't do anything useful.  Making some practical use out of this
feature is left as an exercise to the interested readers ;-).  See
also FILE_FLAG_DELETE_ON_CLOSE.

(Note that above I said "almost" exactly like Posix, and that's
because a Posix filesystem will not show the file in `ls' after it was
deleted like that, while Windows does.  All the rest is similar.)

----------------------------- cut here ----------------------------
#include <stdio.h>
#include <errno.h>
#include <windows.h>

int
main (int argc, char *argv[])
{
  HANDLE fh = CreateFile (argc > 1 ? argv[1] : "topen.tst",
                          GENERIC_READ,
                          FILE_SHARE_READ | FILE_SHARE_DELETE,
                          NULL, OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL, NULL);

  if (fh != INVALID_HANDLE_VALUE)
    {
      Sleep (30000);
      CloseHandle (fh);
    }
  else
    fprintf (stderr, "%s: cannot open: %lu\n",
         argc > 1 ? argv[1] : "topen.tst", GetLastError ());

  return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]