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

Replace custom atomicWrite by more robust library call. #334

Merged
merged 2 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions clcache/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import threading
from tempfile import TemporaryFile
from typing import Any, List, Tuple, Iterator
from atomicwrites import atomic_write

VERSION = "4.2.0-dev"

Expand Down Expand Up @@ -117,14 +118,6 @@ def normalizeBaseDir(baseDir):
return None


@contextlib.contextmanager
def atomicWrite(fileName):
tempFileName = fileName + '.new'
with open(tempFileName, 'w') as f:
yield f
os.replace(tempFileName, fileName)


def getCachedCompilerConsoleOutput(path):
try:
with open(path, 'rb') as f:
Expand Down Expand Up @@ -198,7 +191,7 @@ def setManifest(self, manifestHash, manifest):
manifestPath = self.manifestPath(manifestHash)
printTraceStatement("Writing manifest with manifestHash = {} to {}".format(manifestHash, manifestPath))
ensureDirectoryExists(self.manifestSectionDir)
with atomicWrite(manifestPath) as outFile:
with atomic_write(manifestPath, overwrite=True) as outFile:
# Converting namedtuple to JSON via OrderedDict preserves key names and keys order
entries = [e._asdict() for e in manifest.entries()]
jsonobject = {'entries': entries}
Expand Down Expand Up @@ -662,7 +655,7 @@ def __init__(self, fileName):

def save(self):
if self._dirty:
with atomicWrite(self._fileName) as f:
with atomic_write(self._fileName, overwrite=True) as f:
json.dump(self._dict, f, sort_keys=True, indent=4)

def __setitem__(self, key, value):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
install_requires=[
'typing; python_version < "3.5"',
'subprocess.run; python_version < "3.5"',
'atomicwrites',
'pymemcache',
'pyuv',
],
Expand Down