pspp-dev
[Top][All Lists]
Advanced

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

Re: Problem editing file


From: Ben Pfaff
Subject: Re: Problem editing file
Date: Thu, 19 Mar 2009 20:16:55 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Michel Boaventura <address@hidden> writes:

> Looking at the pspp code, and searching on the web about the problem
> of edit the file and save it on windows,
> and I realize that seems like when the user start to change the file,
> pspp creates a new file on the same directory who is
> a copy of the old, and when the user saves, pspp move the tmp file
> over the original.
>
> I see a problem here, because I have some databases with 2GB +-,
> and it will be to much overhead to create a copy and then move it.

There is no other way to do it if you want to make it safe and
keep the SPSS file format.  We can do it, if you are willing to
risk losing the original copy if something goes wrong in the
middle of the operation, or if you are willing to abandon the
SPSS data file format.  But I do not think that either one of
those is a good choice.

> Other issue is that on windows there is no way to overwrite, rename or
> remove an open file. You MUST close it first.

I understand this.  The funny thing is that I don't see what we
are doing incorrectly.  There is only one function that renames a
file in PSPP, which is replace_file_commit().  In turn, there are
only one function related to system files that calls
replace_file_commit(), which is close_writer() in
sys-file-writer.c.  And that function closes the file just above
the spot where it renames over it.

I guess that we must have an additional file handle open
somewhere that has the file open for reading.  On GNU/Linux, I
tried running strace on psppire to see if could figure out what
was going on.  When the GUI came up, I opened a .sav file and
then clicked on the Save button.  Here's part of the output:

    open("/home/blp/pspp/pspp.git/_build/tmp.sav", O_RDONLY|O_LARGEFILE) = 9
    close(9)                                = 0

Opened tmp.sav then closed it.

    open("/home/blp/pspp/pspp.git/_build/tmp.sav", O_RDONLY|O_LARGEFILE) = 8
    close(8)                                = 0

Again (why again?).

    open("/home/blp/pspp/pspp.git/_build/tmp.sav", O_RDONLY|O_LARGEFILE) = 8
    open("/home/blp/pspp/pspp.git/_build/tmp.sav.tmpQDf4qk", 
O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0666) = 9
    close(8)                                = 0
    close(9)                                = 0

Opened it again, wrote to a temp file, closed both.

    rename("/home/blp/pspp/pspp.git/_build/tmp.sav.tmpQDf4qk", 
"/home/blp/pspp/pspp.git/_build/tmp.sav") = 0

Renamed the temp file over the original.  Note that neither file
was open at the time.

Does it take something more complex than Open followed by Save to
trigger the problem?
-- 
Ben Pfaff 
http://benpfaff.org




reply via email to

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