[PythonCAD] Post nineteenth release plans
Eric Wilhelm
ewilhelm at sbcglobal.net
Wed Nov 17 00:15:48 CET 2004
# The following was supposedly scribed by
# Art Haas
# on Tuesday 16 November 2004 09:24 am:
>A better approach
>would be to save the file with a temporary name, and if that save is
>successful then make the backup and rename the temporary file to the
>correct name. This way, the existing file is not tampered with until
> the new file has been completely saved, so any glitches in saving
> the new file will not require you to rename a backup copy.
One caveat in this scheme: You cannot save into a symlink (or a hard
link for that matter.)
Maybe this is solved by getting all of the XML into an in-memory
string, and then open(file, 'w') the file and write into it.
However, here I'm assuming that your main concern about failed saves
is during creation of the XML.
If you really need an atomic write action, then you would have to
follow a symlink back to the original and perform your os.rename()
operation there. However, readlink() only works on symlinks, not
hard links, so this scheme doesn't do everything that open(file, 'w')
does.
Let's forget about links for a second and just note that using a
rename will lose any existing permissions on a file, creating
problems where a file is shared between users (if I set a file as a+r
and that is not the default of my umask, then pythoncad will make my
setting go away whenever I save.) There is also an issue of who
saves the file (I believe any user can write into a file with a+w
permissions, but only the owner can remove it (or move, or rename on
top of it.)) Also, note the implications of same on your backup file
strategy. Maybe you need to actually open() the backup and then read
the current file into it, then open() the destination file and write
the new XML. Then, as long as you have write permission on both
files, everything is okay, regardless of who owns them.
--Eric
--
The opinions expressed in this e-mail were randomly generated by
the computer and do not necessarily reflect the views of its owner.
--Management
More information about the PythonCAD
mailing list