Write coredata transactionally. Closes #3511.

pull/3461/head
Jussi Pakkanen 7 years ago
parent 7e8c099387
commit e3be7f7021
  1. 11
      mesonbuild/coredata.py
  2. 4
      mesonbuild/environment.py
  3. 6
      mesonbuild/mesonmain.py

@ -354,10 +354,19 @@ def load(build_dir):
def save(obj, build_dir): def save(obj, build_dir):
filename = os.path.join(build_dir, 'meson-private', 'coredata.dat') filename = os.path.join(build_dir, 'meson-private', 'coredata.dat')
prev_filename = filename + '.prev'
tempfilename = filename + '~'
if obj.version != version: if obj.version != version:
raise MesonException('Fatal version mismatch corruption.') 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) pickle.dump(obj, f)
f.flush()
os.fsync(f.fileno())
os.replace(tempfilename, filename)
return filename
def get_builtin_options(): def get_builtin_options():
return list(builtin_options.keys()) return list(builtin_options.keys())

@ -261,7 +261,6 @@ def search_version(text):
class Environment: class Environment:
private_dir = 'meson-private' private_dir = 'meson-private'
log_dir = 'meson-logs' 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): def __init__(self, source_dir, build_dir, main_script_launcher, options, original_cmd_line_args):
self.source_dir = source_dir self.source_dir = source_dir
@ -335,8 +334,7 @@ class Environment:
return self.cross_info is not None return self.cross_info is not None
def dump_coredata(self): def dump_coredata(self):
coredata.save(self.coredata, self.get_build_dir()) return coredata.save(self.coredata, self.get_build_dir())
return os.path.join(self.get_build_dir(), Environment.coredata_file)
def get_script_dir(self): def get_script_dir(self):
import mesonbuild.scripts import mesonbuild.scripts

@ -204,7 +204,11 @@ class MesonApp:
g.run_postconf_scripts() g.run_postconf_scripts()
except: except:
if 'cdf' in locals(): 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 raise
def run_script_command(args): def run_script_command(args):

Loading…
Cancel
Save