Re: Win32 rename()/unlink() questions - Mailing list pgsql-hackers

From Mike Mascari
Subject Re: Win32 rename()/unlink() questions
Date
Msg-id 3D8B44CC.6070802@mascari.com
Whole thread Raw
In response to Re: Win32 rename()/unlink() questions  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-hackers
Stephan Szabo wrote:
> On Fri, 20 Sep 2002, Mike Mascari wrote:
> 
> 
>>I think that's a rather poor description. I think it just means
>>that if the file is opened once via CreateFile() with
>>FILE_SHARE_DELETE, then any subsequent CreateFile() calls will
>>fail unless they too have FILE_SHARE_DELETE. In other words, if
>>one of us can delete this file while its open, any of us can.
> 
> 
> The question is, what happens if two people have the file open
> and one goes and tries to delete it?  Can the other still read
> from it?

Yes. I just tested it and it worked. I'll test Bruce's scenario 
as well:

foo contains: "FOO"
bar contains: "BAR"

1. Process 1 opens "foo"
2. Process 2 opens "foo"
3. Process 1 calls MoveFile("foo", "foo2");
4. Process 3 opens "foo" <- Successful?
5. Process 1 calls MoveFile("bar", "foo");
6. Process 4 opens "foo" <- Successful?
7. Process 1 calls DeleteFile("foo2");
8. Process 1, 2, 3, 4 all read from their respective handles.

I think the thing to worry about is a race condition between the 
two MoveFile() attempts. A very ugly hack would be to loop in a 
CreateFile() in an attempt to open "foo", giving up if the error 
is not a NOT EXISTS error code.

Mike Mascari
mascarm@mascari.com



pgsql-hackers by date:

Previous
From: Justin Clift
Date:
Subject: Re: Having no luck with getting pgbench to run multipletimes
Next
From: Bruce Momjian
Date:
Subject: Re: Win32 rename()/unlink() questionst