1
Fork 0

bootstrap: write texts to a .tmp file first for atomicity

If you are using a hard-linked file as your config.toml, this change will affect the way other instances of the file is modified.
The original version would modify all other instances whereas the new version will leave others unchanged, reducing the ref count by one.

Signed-off-by: NODA, Kai <nodakai@gmail.com>
This commit is contained in:
NODA, Kai 2018-06-23 16:51:19 +08:00
parent fc491526dd
commit bcb8a06ef7
2 changed files with 13 additions and 5 deletions

View file

@ -432,7 +432,7 @@ for section_key in config:
# order that we read it in.
p("")
p("writing `config.toml` in current directory")
with open('config.toml', 'w') as f:
with bootstrap.output('config.toml') as f:
for section in section_order:
if section == 'target':
for target in targets:
@ -442,7 +442,7 @@ with open('config.toml', 'w') as f:
for line in sections[section]:
f.write(line + "\n")
with open('Makefile', 'w') as f:
with bootstrap.output('Makefile') as f:
contents = os.path.join(rust_dir, 'src', 'bootstrap', 'mk', 'Makefile.in')
contents = open(contents).read()
contents = contents.replace("$(CFG_SRC_DIR)", rust_dir + '/')