aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-05-15 23:27:42 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2018-05-21 00:48:25 +0300
commite3be7f7021e6fe39509460f1187007ce4c2d1681 (patch)
tree90c412184a5540c69b1f8cf6f853e91d2ce48cd9 /mesonbuild
parent7e8c099387ffcdfbdc55e3ef550cf7e8ab0e848d (diff)
downloadmeson-e3be7f7021e6fe39509460f1187007ce4c2d1681.zip
meson-e3be7f7021e6fe39509460f1187007ce4c2d1681.tar.gz
meson-e3be7f7021e6fe39509460f1187007ce4c2d1681.tar.bz2
Write coredata transactionally. Closes #3511.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/coredata.py11
-rw-r--r--mesonbuild/environment.py4
-rw-r--r--mesonbuild/mesonmain.py6
3 files changed, 16 insertions, 5 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index a1dbac8..f3313f3 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -354,10 +354,19 @@ def load(build_dir):
def save(obj, build_dir):
filename = os.path.join(build_dir, 'meson-private', 'coredata.dat')
+ prev_filename = filename + '.prev'
+ tempfilename = filename + '~'
if obj.version != version:
raise MesonException('Fatal version mismatch corruption.')
- with open(filename, 'wb') as f:
+ if os.path.exists(filename):
+ import shutil
+ shutil.copyfile(filename, prev_filename)
+ with open(tempfilename, 'wb') as f:
pickle.dump(obj, f)
+ f.flush()
+ os.fsync(f.fileno())
+ os.replace(tempfilename, filename)
+ return filename
def get_builtin_options():
return list(builtin_options.keys())
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 15b3737..045be82 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -261,7 +261,6 @@ def search_version(text):
class Environment:
private_dir = 'meson-private'
log_dir = 'meson-logs'
- coredata_file = os.path.join(private_dir, 'coredata.dat')
def __init__(self, source_dir, build_dir, main_script_launcher, options, original_cmd_line_args):
self.source_dir = source_dir
@@ -335,8 +334,7 @@ class Environment:
return self.cross_info is not None
def dump_coredata(self):
- coredata.save(self.coredata, self.get_build_dir())
- return os.path.join(self.get_build_dir(), Environment.coredata_file)
+ return coredata.save(self.coredata, self.get_build_dir())
def get_script_dir(self):
import mesonbuild.scripts
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
index 2b6281d..82f5031 100644
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -204,7 +204,11 @@ class MesonApp:
g.run_postconf_scripts()
except:
if 'cdf' in locals():
- os.unlink(cdf)
+ old_cdf = cdf + '.prev'
+ if os.path.exists(old_cdf):
+ os.replace(old_cdf, cdf)
+ else:
+ os.unlink(cdf)
raise
def run_script_command(args):