Skip to content

Commit 542a3c3

Browse files
authored
Fixed FIleExistsError in the _save method (#3)
Fixed FIleExistsError in the _save method on Windows
1 parent c81e3e7 commit 542a3c3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

jsonstore.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ def _save(self):
5353
with open(temp, "wb") as store:
5454
output = json.dumps(self._data, indent=self._indent)
5555
store.write(output.encode("utf-8"))
56-
os.rename(temp, self._path)
56+
57+
if sys.version_info >= (3, 3):
58+
os.replace(temp, self._path)
59+
elif os.name == "windows":
60+
os.remove(self._path)
61+
os.rename(temp, self._path)
62+
else:
63+
os.rename(temp, self._path)
5764

5865
def __init__(self, path, indent=2, auto_commit=True):
5966
self.__dict__.update(

0 commit comments

Comments
 (0)