On Feb 4, 12:46 pm, "Edward K. Ream" <[email protected]> wrote:
> On Feb 4, 11:21 am, "Edward K. Ream" <[email protected]> wrote:
> The bad news is that...createBackupFile can still create a race condition:
The race condition should be fixed on the trunk at 2876. As expected,
the fix was to write the original .leo to the temporary (backup) file
before closing the file descriptor returned by mkstemp. Here is the
code, with error checking omitted for clarity:
fd,backupName = tempfile.mkstemp(text=False)
f = open(fileName,'rb') # rb is essential.
s = f.read()
f.close()
os.write(fd,s)
os.close(fd)
Some notes:
1. According to a note in the os module's documentation mkstemp and
the os methods *are* available on MacOs because MacOs is equivalent to
Linux, at least for this purpose. That's very good news.
2. The code above must be sure to copy the file exactly. Otherwise,
restoring the file from backup could result in unicode errors!
Apparently, opening fileName (the original .leo file) in 'rb' mode is
both necessary and sufficient to ensure a faithful file copy.
> The good new is that it was easier than expected to remove
> g.makeAllNonExistentDirectories from
g.utils_rename. Details later.
Removing the call to g.makeAllNonExistentDirectories in g.utils_rename
does indeed have global effects. Happily, there were only three
callers of g.utils_rename:
- handleWriteLeoFileException: No change needed because this should
not create directories.
- x.rename: no longer used! I removed it completely.
- g.update_file_if_changed: This is called only from
tangle.put_all_roots. I added call to g.makeAllNonExistentDirectories
there.
I also removed the unused 'mode' argument from utils_rename. As a
result, the code is nothing but a thin wrapper around shutil.move.
In short, the code should be significantly better and simpler than it
was before.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.