Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit 24315e7

Browse files
committed
Replace custom atomicWrite by more robust library call.
1 parent 0ab5d78 commit 24315e7

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

clcache/__main__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# full text of which is available in the accompanying LICENSE file at the
77
# root directory of this project.
88
#
9+
from atomicwrites import atomic_write
910
from collections import defaultdict, namedtuple
1011
from ctypes import windll, wintypes
1112
from shutil import copyfile, copyfileobj, rmtree, which
@@ -117,14 +118,6 @@ def normalizeBaseDir(baseDir):
117118
return None
118119

119120

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-
128121
def getCachedCompilerConsoleOutput(path):
129122
try:
130123
with open(path, 'rb') as f:
@@ -198,7 +191,7 @@ def setManifest(self, manifestHash, manifest):
198191
manifestPath = self.manifestPath(manifestHash)
199192
printTraceStatement("Writing manifest with manifestHash = {} to {}".format(manifestHash, manifestPath))
200193
ensureDirectoryExists(self.manifestSectionDir)
201-
with atomicWrite(manifestPath) as outFile:
194+
with atomic_write(manifestPath, overwrite=True) as outFile:
202195
# Converting namedtuple to JSON via OrderedDict preserves key names and keys order
203196
entries = [e._asdict() for e in manifest.entries()]
204197
jsonobject = {'entries': entries}
@@ -662,7 +655,7 @@ def __init__(self, fileName):
662655

663656
def save(self):
664657
if self._dirty:
665-
with atomicWrite(self._fileName) as f:
658+
with atomic_write(self._fileName, overwrite=True) as f:
666659
json.dump(self._dict, f, sort_keys=True, indent=4)
667660

668661
def __setitem__(self, key, value):

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
install_requires=[
1717
'typing; python_version < "3.5"',
1818
'subprocess.run; python_version < "3.5"',
19+
'atomicwrites',
1920
'pymemcache',
2021
'pyuv',
2122
],

0 commit comments

Comments
 (0)