Skip to content

Safer config saving#6987

Merged
feerrenrut merged 5 commits into
masterfrom
i3165-saferConfigSaving
Apr 4, 2017
Merged

Safer config saving#6987
feerrenrut merged 5 commits into
masterfrom
i3165-saferConfigSaving

Conversation

@feerrenrut

Copy link
Copy Markdown
Contributor

Fixes #3165

This supersedes #5916. Rather than use osreplace use MoveFileExW called with ctypes

Generally the approach is to lessen the chance that ALL config is lost if NVDA is interrupted during the saving process. This is done by first writing to a temporary file and then using this to replace the target config file.

There is a chance that some recently changed configuration will not be saved, if the saving process is interrupted while the temp file is being written. However this will no longer result in ALL config being lost.

bramd and others added 4 commits March 15, 2017 10:07
…refs issue #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.
So that no miscDeps update is required, use moveFileEx through ctypes.
Comment thread source/fileUtils.py Outdated
@@ -0,0 +1,24 @@
#fileUtils.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2006-2016 NV Access Limited

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should instead be:

+#Copyright (C) 2017 NV Access Limited, Bram Duvigneau

Comment thread source/fileUtils.py
from logHandler import log

@contextmanager
def FaultTolerantFile(name):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a docstring with details on what this is/does and maybe example usage. The Python term for one of these with things is "context manager".

Comment thread source/fileUtils.py Outdated
f.flush()
os.fsync(f)
f.close()
MOVEFILE_REPLACE_EXISTING = 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this constant outside the function.

@Brian1Gaff

Brian1Gaff commented Mar 17, 2017 via email

Copy link
Copy Markdown

feerrenrut added a commit that referenced this pull request Mar 17, 2017
Re issue: #3165
Merge branch 'i3165-saferConfigSaving' into next
@feerrenrut feerrenrut merged commit 40e69d5 into master Apr 4, 2017
@nvaccessAuto nvaccessAuto added this to the 2017.2 milestone Apr 4, 2017
@feerrenrut feerrenrut deleted the i3165-saferConfigSaving branch April 4, 2017 07:28
feerrenrut added a commit that referenced this pull request Apr 4, 2017
- Deprecated code removed:
 - PR #6878: `speech.REASON_*` constants, `controlTypes.REASON_*` should be used
   instead. (issue #6846)
 - PR #6877: `i18nName` for synth settings, `displayName` and
   `displayNameWithAccelerator` should be used instead. (issues #6846, #5185)
 - PR #6876: `config.validateConfig`. (issues #6846, #667)
 - PR #6875: `config.save`. (issue #6846)

- PR #6914: Support Windows Calculator on Windows 10 Enterprise LTSB (Long-Term
  Servicing Branch) and Server. (issue #6914)
- PR #6987: Reduced the chance of configuration file being corrupted when
  Windows shuts down. Configuration files are now written to a temporary
  file before replacing the actual configuration file. (issue #3165)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants