Skip to content

Commit ef2fb81

Browse files
committedJan 6, 2016
don't lose all the data if you write without a get
1 parent a52f395 commit ef2fb81

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎nikola/state.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,26 @@ def __init__(self, path):
5151

5252
def get(self, key):
5353
"""Get data stored in key."""
54-
if os.path.isfile(path):
55-
with open(path) as inf:
56-
self.data = json.load(inf)
5754
return self.data.get(key)
5855

5956
def set(self, key, value):
6057
"""Store value in key."""
58+
self._read()
6159
self.data[key] = value
6260
self._save()
6361

6462
def delete(self, key):
6563
"""Delete key and the value it contains."""
64+
self._read()
6665
if key in self.data:
6766
self.data.pop(key)
6867
self._save()
6968

69+
def _read(self)
70+
if os.path.isfile(self._path):
71+
with open(self._path) as inf:
72+
self.data = json.load(inf)
73+
7074
def _save(self):
7175
tpath = self._path + '.tmp'
7276
with open(tpath, 'w') as outf:

0 commit comments

Comments
 (0)
Please sign in to comment.