Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Bruce Momjian
Mike Mascari wrote: > > 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"

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Bruce Momjian
Mike Mascari wrote: > 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 re

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Mike Mascari
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:

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Mike Mascari
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_DE

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Jan Wieck
Mike Mascari wrote: > instead of fopen(). I'm not sure about ME, but I suspect it > behaves similarly to 95/98. I just checked with Katie and the good news (tm) is that the Win32 port we did here at PeerDirect doesn't support 95/98 and ME anyway. It does support NT4, 2000 and XP. So don't bother

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Bruce Momjian
Mike Mascari wrote: > Bruce Momjian wrote: > > I don't think we are not going to be supporting Win9X so there isn't an > > issue there. We will be supporting Win2000/NT/XP. > > > > I don't understand FILE_SHARE_DELETE. I read the description at: > > > > >http://msdn.microsoft.com/library/

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Stephan Szabo
On Fri, 20 Sep 2002, Mike Mascari wrote: > Bruce Momjian wrote: > > I don't think we are not going to be supporting Win9X so there isn't an > > issue there. We will be supporting Win2000/NT/XP. > > > > I don't understand FILE_SHARE_DELETE. I read the description at: > > > > >http://msdn.mi

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Mike Mascari
Bruce Momjian wrote: > I don't think we are not going to be supporting Win9X so there isn't an > issue there. We will be supporting Win2000/NT/XP. > > I don't understand FILE_SHARE_DELETE. I read the description at: > > >http://msdn.microsoft.com/library/default.asp?url=/library/en-us/f

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Bruce Momjian
I don't think we are not going to be supporting Win9X so there isn't an issue there. We will be supporting Win2000/NT/XP. I don't understand FILE_SHARE_DELETE. I read the description at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp but

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-20 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > ... let you do the replace and keep reading (at the penalty that > you've now got to have a way to know when to remove the > various s) That is the hard part. Mike's description omitted one crucial step: 6. The old "foo" goes away when the last open f

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Mike Mascari
Stephan Szabo wrote: > On Fri, 20 Sep 2002, Mike Mascari wrote: >> >>Yes! Indeed that does work. > > > Thinking back, I think that may still fail on Win95 (using MoveFile). > Once in the past I had to work on (un)installers for Win* and I > vaguely remember Win95 being more strict than Win98 but

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Stephan Szabo
On Fri, 20 Sep 2002, Mike Mascari wrote: > Stephan Szabo wrote: > > On Fri, 20 Sep 2002, Mike Mascari wrote: > >>So far, MoveFileEx("foo", "bar", MOVEFILE_REPLACE_EXISTING) > >>returns "Access Denied" when Process 1 attempts the rename. But > >>I'm continuing to investigate the possibilities... >

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Mike Mascari
Stephan Szabo wrote: > On Fri, 20 Sep 2002, Mike Mascari wrote: >>Bruce Momjian wrote: >>>Mike Mascari wrote: Actually, looking at the pg_pwd code, you want to determine a way for: 1. Process 1 opens "foo" 2. Process 2 opens "foo" 3. Process 1 creates "bar" 4. Process

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Stephan Szabo
On Fri, 20 Sep 2002, Mike Mascari wrote: > Bruce Momjian wrote: > > Mike Mascari wrote: > > > >>Actually, looking at the pg_pwd code, you want to determine a > >>way for: > >> > >>1. Process 1 opens "foo" > >>2. Process 2 opens "foo" > >>3. Process 1 creates "bar" > >>4. Process 1 renames "bar"

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Mike Mascari
Bruce Momjian wrote: > Mike Mascari wrote: > >>Actually, looking at the pg_pwd code, you want to determine a >>way for: >> >>1. Process 1 opens "foo" >>2. Process 2 opens "foo" >>3. Process 1 creates "bar" >>4. Process 1 renames "bar" to "foo" >>5. Process 2 can continue to read data from the op

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Bruce Momjian
Mike Mascari wrote: > Actually, looking at the pg_pwd code, you want to determine a > way for: > > 1. Process 1 opens "foo" > 2. Process 2 opens "foo" > 3. Process 1 creates "bar" > 4. Process 1 renames "bar" to "foo" > 5. Process 2 can continue to read data from the open file handle > and get

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Mike Mascari
Mike Mascari wrote: > Bruce Momjian wrote: > >> Mike Mascari wrote: >> >>> I will do some testing with concurrency and let you know. But don't >>> get your hopes up. This is one of the many advantages that >>> TABLESPACEs have when more than one relation is stored in a single >>> DATAFILE. The

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Mike Mascari
Bruce Momjian wrote: > Mike Mascari wrote: > >>I will do some testing with concurrency and let you know. But >>don't get your hopes up. This is one of the many advantages that >>TABLESPACEs have when more than one relation is stored in a >>single DATAFILE. There was Oracle for MS-DOS, after al

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Bruce Momjian
Mike Mascari wrote: > I read the article and did not come away with that conclusion. > The article describes using the MOVEFILE_DELAY_UNTIL_REBOOT > flag, which was created for the express purpose of allowing a > SETUP.EXE to remove itself, or rather tell Windows to remove it > on the next reb

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Mike Mascari
Bruce Momjian wrote: > Bruce Momjian wrote: >>> >>>unlink() just calls DeleteFile() which will error if: >>> >>>1. The target file is in use >>> >>>CreateFile() has the option: >>> >>>FILE_FLAG_DELETE_ON_CLOSE >>> >>>which might be able to be used to simulate traditional unlink() >>>behavior. >>

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Bruce Momjian
Bruce Momjian wrote: > > > Second, when you unlink() a file on Win32, do applications continue > > > accessing the old file contents if they had the file open before the > > > unlink? > > > > > > > unlink() just calls DeleteFile() which will error if: > > > > 1. The target file is in use > > >

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-19 Thread Bruce Momjian
Mike Mascari wrote: > Bruce Momjian wrote: > > I am working with several groups getting the Win32 port ready for 7.4 > > and I have a few questions: > > > > What is the standard workaround for the fact that rename() isn't atomic > > on Win32? Do we need to create our own locking around the > > r

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-18 Thread Mike Mascari
Christopher Kings-Lynne wrote: >>On Wed, Sep 18, 2002 at 08:01:42PM -0400, Bruce Momjian wrote: >> >> >>>Second, when you unlink() a file on Win32, do applications continue >>>accessing the old file contents if they had the file open before the >>>unlink? >> >>I'm pretty sure it errors with 'file

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-18 Thread Mike Mascari
Bruce Momjian wrote: > I am working with several groups getting the Win32 port ready for 7.4 > and I have a few questions: > > What is the standard workaround for the fact that rename() isn't atomic > on Win32? Do we need to create our own locking around the > reading/writing of files that are n

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-18 Thread Christopher Kings-Lynne
> On Wed, Sep 18, 2002 at 08:01:42PM -0400, Bruce Momjian wrote: > > > Second, when you unlink() a file on Win32, do applications continue > > accessing the old file contents if they had the file open before the > > unlink? > > I'm pretty sure it errors with 'file in use'. Pretty ugly, huh? Yeah

Re: [HACKERS] Win32 rename()/unlink() questions

2002-09-18 Thread Ross J. Reedstrom
On Wed, Sep 18, 2002 at 08:01:42PM -0400, Bruce Momjian wrote: > Second, when you unlink() a file on Win32, do applications continue > accessing the old file contents if they had the file open before the > unlink? I'm pretty sure it errors with 'file in use'. Pretty ugly, huh? Ross -

[HACKERS] Win32 rename()/unlink() questions

2002-09-18 Thread Bruce Momjian
I am working with several groups getting the Win32 port ready for 7.4 and I have a few questions: What is the standard workaround for the fact that rename() isn't atomic on Win32? Do we need to create our own locking around the reading/writing of files that are normally updated in place using re