|
6 | 6 | # full text of which is available in the accompanying LICENSE file at the
|
7 | 7 | # root directory of this project.
|
8 | 8 | #
|
| 9 | +from atomicwrites import atomic_write |
9 | 10 | from collections import defaultdict, namedtuple
|
10 | 11 | from ctypes import windll, wintypes
|
11 | 12 | from shutil import copyfile, copyfileobj, rmtree, which
|
@@ -117,14 +118,6 @@ def normalizeBaseDir(baseDir):
|
117 | 118 | return None
|
118 | 119 |
|
119 | 120 |
|
120 |
| -@contextlib.contextmanager |
121 |
| -def atomicWrite(fileName): |
122 |
| - tempFileName = fileName + '.new' |
123 |
| - with open(tempFileName, 'w') as f: |
124 |
| - yield f |
125 |
| - os.replace(tempFileName, fileName) |
126 |
| - |
127 |
| - |
128 | 121 | def getCachedCompilerConsoleOutput(path):
|
129 | 122 | try:
|
130 | 123 | with open(path, 'rb') as f:
|
@@ -198,7 +191,7 @@ def setManifest(self, manifestHash, manifest):
|
198 | 191 | manifestPath = self.manifestPath(manifestHash)
|
199 | 192 | printTraceStatement("Writing manifest with manifestHash = {} to {}".format(manifestHash, manifestPath))
|
200 | 193 | ensureDirectoryExists(self.manifestSectionDir)
|
201 |
| - with atomicWrite(manifestPath) as outFile: |
| 194 | + with atomic_write(manifestPath, overwrite=True) as outFile: |
202 | 195 | # Converting namedtuple to JSON via OrderedDict preserves key names and keys order
|
203 | 196 | entries = [e._asdict() for e in manifest.entries()]
|
204 | 197 | jsonobject = {'entries': entries}
|
@@ -662,7 +655,7 @@ def __init__(self, fileName):
|
662 | 655 |
|
663 | 656 | def save(self):
|
664 | 657 | if self._dirty:
|
665 |
| - with atomicWrite(self._fileName) as f: |
| 658 | + with atomic_write(self._fileName, overwrite=True) as f: |
666 | 659 | json.dump(self._dict, f, sort_keys=True, indent=4)
|
667 | 660 |
|
668 | 661 | def __setitem__(self, key, value):
|
|
0 commit comments