Only save wallet if modified
This commit is contained in:
parent
f710d872c7
commit
b5e0363f85
|
@ -51,6 +51,7 @@ class WalletStorage(PrintError):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
self.path = path
|
self.path = path
|
||||||
self.file_exists = False
|
self.file_exists = False
|
||||||
|
self.modified = False
|
||||||
self.print_error("wallet path", self.path)
|
self.print_error("wallet path", self.path)
|
||||||
if self.path:
|
if self.path:
|
||||||
self.read(self.path)
|
self.read(self.path)
|
||||||
|
@ -105,16 +106,22 @@ class WalletStorage(PrintError):
|
||||||
return
|
return
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if value is not None:
|
if value is not None:
|
||||||
|
if self.data.get(key) != value:
|
||||||
|
self.modified = True
|
||||||
self.data[key] = copy.deepcopy(value)
|
self.data[key] = copy.deepcopy(value)
|
||||||
elif key in self.data:
|
elif key in self.data:
|
||||||
|
self.modified = True
|
||||||
self.data.pop(key)
|
self.data.pop(key)
|
||||||
if save:
|
if save:
|
||||||
self.write()
|
self.write()
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
assert not threading.currentThread().isDaemon()
|
assert not threading.currentThread().isDaemon()
|
||||||
temp_path = "%s.tmp.%s" % (self.path, os.getpid())
|
if not self.modified:
|
||||||
|
return
|
||||||
|
with self.lock:
|
||||||
s = json.dumps(self.data, indent=4, sort_keys=True)
|
s = json.dumps(self.data, indent=4, sort_keys=True)
|
||||||
|
temp_path = "%s.tmp.%s" % (self.path, os.getpid())
|
||||||
with open(temp_path, "w") as f:
|
with open(temp_path, "w") as f:
|
||||||
f.write(s)
|
f.write(s)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
@ -128,6 +135,7 @@ class WalletStorage(PrintError):
|
||||||
if 'ANDROID_DATA' not in os.environ:
|
if 'ANDROID_DATA' not in os.environ:
|
||||||
import stat
|
import stat
|
||||||
os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE)
|
os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE)
|
||||||
|
self.print_error("saved")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue