Split out file and URI handling helpers
with_wait_cursor(): better error reporting

Improve backtraces from functions using this decorator.
Save robustness: via tempfile, fsync()ed backup

Addresses https://gna.org/bugs/?19465

Save all files using a tempfile with rename-over if possible to make saving
on flaky systems which use ext4 a trifle more reliable. At least for newer
ext4 versions, renaming over an existing file supposedly causes the OS to
aggressively flush data blocks to disk so that power outages hopefully
won't lose data.

Also make backup copies (yes, copies), and try to fsync them as we make
them. This provides an additional safety net, and it makes sense to do an
fsync for the copy operation at the same time we expect newer ext4
filesystems to aggressively sync data.

(Why associate the manual fsync with the backup file copyi and not the
initial write? Well, pretty much any save operation in MyPaint uses
external libs and filenames.)

If users hate this behaviour, or it takes too long for big files, we can
reduce the level of paranoia a bit. I guess. I mean, it's not as if fsync()
actually buys you any safety anyway:
https://mail.zope.org/pipermail/zodb-dev/2004-July/007689.html