Skip to content

Commit

Permalink
[Lib][Qt] Pulled some minor tweaks from upstream to wallet storage
Browse files Browse the repository at this point in the history
Deleting a wallet from outside the app while it's running could cause
weirdness (see: spesmilo#4984 and
spesmilo#5082). Follow ups to fix
that.
  • Loading branch information
cculianu committed Feb 8, 2019
1 parent 966cfc8 commit 0698688
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2677,11 +2677,13 @@ def remove_wallet(self):
def _delete_wallet(self, password):
wallet_path = self.wallet.storage.path
basename = os.path.basename(wallet_path)
self.gui_object.daemon.stop_wallet(wallet_path)
r = self.gui_object.daemon.delete_wallet(wallet_path) # implicitly also calls stop_wallet
self.close()
os.unlink(wallet_path)
self.update_recently_visited(wallet_path) # this ensures it's deleted from the menu
self.show_error("Wallet removed:" + basename)
if r:
self.show_error(_("Wallet removed: {}").format(basename))
else:
self.show_error(_("Wallet file not found: {}").format(basename))

@protected
def show_seed_dialog(self, password):
Expand Down
7 changes: 7 additions & 0 deletions lib/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ def add_wallet(self, wallet):
def get_wallet(self, path):
return self.wallets.get(path)

def delete_wallet(self, path):
self.stop_wallet(path)
if os.path.exists(path):
os.unlink(path)
return True
return False

def stop_wallet(self, path):
# Issue #659 wallet may already be stopped.
if path in self.wallets:
Expand Down
3 changes: 3 additions & 0 deletions lib/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ def _write(self):
os.fsync(f.fileno())

mode = os.stat(self.path).st_mode if self.file_exists() else stat.S_IREAD | stat.S_IWRITE
if not self.file_exists():
# See: https://github.com/spesmilo/electrum/issues/5082
assert not os.path.exists(self.path)
# perform atomic write on POSIX systems
try:
os.rename(temp_path, self.path)
Expand Down

0 comments on commit 0698688

Please sign in to comment.