forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save configuration profiles and gesture maps as an atomic operation (…
…refs issue nvaccess#3165) Instead of directly writing the file, a temporary file is created and moved to the final location. This prevents corrupt configuration files being written. Added a fileUtils module with just a FaultTolerantFile context manager for now to facilitate this pattern. Please update miscDependencies submodule to a revision that includes the osmove module.
- Loading branch information
Showing
4 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
import osreplace | ||
from contextlib import contextmanager | ||
from tempfile import NamedTemporaryFile | ||
from logHandler import log | ||
|
||
@contextmanager | ||
def FaultTolerantFile(name): | ||
dirpath, filename = os.path.split(name) | ||
with NamedTemporaryFile(dir=dirpath, prefix=filename, suffix='.tmp', delete=False) as f: | ||
log.debug(f.name) | ||
yield f | ||
f.flush() | ||
os.fsync(f) | ||
f.close() | ||
osreplace.replace(f.name, name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters