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

From Mike Mascari
Subject Re: Win32 rename()/unlink() questions
Date
Msg-id 3D8B4C74.2050708@mascari.com
Whole thread Raw
In response to Re: Win32 rename()/unlink() questions  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Responses Re: Win32 rename()/unlink() questions  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: Win32 rename()/unlink() questions  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
I wrote:
> Stephan Szabo wrote:>>
>> 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.

Process 1: "FOO"
Process 2: "FOO"
Process 3: Error - File does not exist
Process 4: "BAR"

Its interesting in that it allows for Unix-style rename() and 
unlink() behavior, but with a race condition. Without Stephan's 
two MoveFile() trick and the FILE_SHARE_DELETE flag, however, 
the result would be Access Denied. Are the places in the backend 
that use rename() and unlink() renaming and unlinking files that 
are only opened for a brief moment by other backends?

Mike Mascari
mascarm@mascari.com



pgsql-hackers by date:

Previous
From: "Shridhar Daithankar"
Date:
Subject: Re: Improving speed of copy
Next
From: "Jonah H. Harris"
Date:
Subject: Re: Improving speed of copy