app: save qubes.xml with utils.replace_file()
That takes care of the missing fsync() calls. Fixes QubesOS/qubes-issues#3376
This commit is contained in:
parent
9b6d082673
commit
12d117b20a
19
qubes/app.py
19
qubes/app.py
@ -29,7 +29,6 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import uuid
|
import uuid
|
||||||
@ -1102,18 +1101,12 @@ class Qubes(qubes.PropertyHolder):
|
|||||||
if not self.__locked_fh:
|
if not self.__locked_fh:
|
||||||
self._acquire_lock(for_save=True)
|
self._acquire_lock(for_save=True)
|
||||||
|
|
||||||
fh_new = tempfile.NamedTemporaryFile(
|
with qubes.utils.replace_file(self._store, permissions=0o660,
|
||||||
prefix=self._store, delete=False)
|
close_on_success=False) as fh_new:
|
||||||
lxml.etree.ElementTree(self.__xml__()).write(
|
lxml.etree.ElementTree(self.__xml__()).write(
|
||||||
fh_new, encoding='utf-8', pretty_print=True)
|
fh_new, encoding='utf-8', pretty_print=True)
|
||||||
fh_new.flush()
|
with suppress(KeyError): # group not found
|
||||||
try:
|
os.fchown(fh_new.fileno(), -1, grp.getgrnam('qubes').gr_gid)
|
||||||
os.chown(fh_new.name, -1, grp.getgrnam('qubes').gr_gid)
|
|
||||||
os.chmod(fh_new.name, 0o660)
|
|
||||||
except KeyError: # group 'qubes' not found
|
|
||||||
# don't change mode if no 'qubes' group in the system
|
|
||||||
pass
|
|
||||||
os.rename(fh_new.name, self._store)
|
|
||||||
|
|
||||||
# update stored mtime, in case of multiple save() calls without
|
# update stored mtime, in case of multiple save() calls without
|
||||||
# loading qubes.xml again
|
# loading qubes.xml again
|
||||||
|
Loading…
Reference in New Issue
Block a user