[Python-ideas] BackupFile

Masklinn masklinn at masklinn.net
Mon Jun 25 14:33:36 CEST 2012

On 2012-06-25, at 14:17 , Kim Gräsman wrote:
> - Would something like this be useful outside of my office?

I'm not sure I correctly understand the purpose of this, and if I do it
seems to be kind-of a hack for "fixing" kind-of crummy code: is it
correct that the goal is to temporarily edit a file (and restore it
later) to change the behavior of *other* pieces of code reading the same

So essentially dynamically scoping the content of a file?

I find the idea rather troublesome/problematic, as it's completely
blind to (and unsafe under) concurrent access, and will be tricky to
handle cleanly wrt filesystem caches and commits.

The initial mail hinted at atomic file replacement *or* backuping a file
and restoring the backup on error, something along the lines of:

    with Backup(settings_file):
    # altered file

    with Backup(settings_file):
        raise Exception("boom")
    # old file is back

in the same way e.g. Emacs will keep "~" files around during edition. That
could have been a ~+1 for me, but the behavior as I understood it
(understanding which may be incorrect, again) I'd be −1 on, it seems too
dangerous and too tied to other issues in the code.

More information about the Python-ideas mailing list