summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2018-06-05 13:47:01 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2018-06-07 00:18:21 +0300
commitd9efee01d0dc08f8e41ef1f0dd239113309135a1 (patch)
treef0162ada56df0a62caf5667800d7d3e651a4dd8e
parent9b791881ed61e3c9c68599c231337ffc8f5769b0 (diff)
downloadmeson-d9efee01d0dc08f8e41ef1f0dd239113309135a1.tar.gz
gettext: Install .mo files atomically
Without this, building a module in a Flatpak app manifest that is a newer version of a module already present in the Flatpak runtime will fail. (The Flatpak file system is a bunch of hard links to readonly files, which can be replaced but not written to.) This instead creates a temporary file in the same directory as the destination (to avoid cross-device renaming errors) and atomically renames the temporary file to the destination, replacing it instead of rewriting it as shutil.copyfile() would do.
-rw-r--r--mesonbuild/scripts/gettext.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/mesonbuild/scripts/gettext.py b/mesonbuild/scripts/gettext.py
index f308c5a3b..593247afd 100644
--- a/mesonbuild/scripts/gettext.py
+++ b/mesonbuild/scripts/gettext.py
@@ -81,9 +81,11 @@ def do_install(src_sub, bld_sub, dest, pkgname, langs):
srcfile = os.path.join(bld_sub, l + '.gmo')
outfile = os.path.join(dest, l, 'LC_MESSAGES',
pkgname + '.mo')
+ tempfile = outfile + '.tmp'
os.makedirs(os.path.dirname(outfile), exist_ok=True)
- shutil.copyfile(srcfile, outfile)
- shutil.copystat(srcfile, outfile)
+ shutil.copyfile(srcfile, tempfile)
+ shutil.copystat(srcfile, tempfile)
+ os.replace(tempfile, outfile)
print('Installing %s to %s' % (srcfile, outfile))
return 0