Merge pull request #8651 from accumulator/issue_8028
config: keep wallets directory stable, regardless of wallet opens in …
This commit is contained in:
@@ -677,7 +677,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
self.recently_visited_menu.setEnabled(bool(len(recent)))
|
||||
|
||||
def get_wallet_folder(self):
|
||||
return os.path.dirname(os.path.abspath(self.wallet.storage.path))
|
||||
return os.path.abspath(self.config.get_datadir_wallet_path())
|
||||
|
||||
def new_wallet(self):
|
||||
try:
|
||||
|
||||
@@ -298,12 +298,23 @@ class WCWalletName(WizardComponent, Logger):
|
||||
self.layout().addStretch(1)
|
||||
|
||||
temp_storage = None # type: Optional[WalletStorage]
|
||||
wallet_folder = os.path.dirname(path)
|
||||
datadir_wallet_folder = self.wizard.config.get_datadir_wallet_path()
|
||||
|
||||
def relative_path(path):
|
||||
new_path = path
|
||||
try:
|
||||
commonpath = os.path.commonpath([path, datadir_wallet_folder])
|
||||
if commonpath == datadir_wallet_folder:
|
||||
# below datadir_wallet_path, make relative
|
||||
new_path = os.path.relpath(path, commonpath)
|
||||
except ValueError:
|
||||
pass
|
||||
return new_path
|
||||
|
||||
def on_choose():
|
||||
_path, __ = QFileDialog.getOpenFileName(self, "Select your wallet file", wallet_folder)
|
||||
_path, __ = QFileDialog.getOpenFileName(self, "Select your wallet file", datadir_wallet_folder)
|
||||
if _path:
|
||||
self.name_e.setText(_path)
|
||||
self.name_e.setText(relative_path(_path))
|
||||
|
||||
def on_filename(filename):
|
||||
# FIXME? "filename" might contain ".." (etc) and hence sketchy path traversals are possible
|
||||
@@ -314,7 +325,7 @@ class WCWalletName(WizardComponent, Logger):
|
||||
self.wallet_is_open = False
|
||||
self.wallet_needs_hw_unlock = False
|
||||
if filename:
|
||||
_path = os.path.join(wallet_folder, filename)
|
||||
_path = os.path.join(datadir_wallet_folder, filename)
|
||||
wallet_from_memory = self.wizard._daemon.get_wallet(_path)
|
||||
try:
|
||||
if wallet_from_memory:
|
||||
@@ -352,6 +363,8 @@ class WCWalletName(WizardComponent, Logger):
|
||||
+ _("Press 'Finish' to create/focus window.")
|
||||
if msg is None:
|
||||
msg = _('Cannot read file')
|
||||
if filename and os.path.isabs(relative_path(_path)):
|
||||
msg += '\n\n' + _('Note: this wallet file is outside the default wallets folder.')
|
||||
msg_label.setText(msg)
|
||||
widget_create_new.setVisible(bool(temp_storage and temp_storage.file_exists()))
|
||||
if user_needs_to_enter_password:
|
||||
@@ -366,15 +379,14 @@ class WCWalletName(WizardComponent, Logger):
|
||||
|
||||
button.clicked.connect(on_choose)
|
||||
button_create_new.clicked.connect(
|
||||
lambda: self.name_e.setText(get_new_wallet_name(wallet_folder))) # FIXME get_new_wallet_name might raise
|
||||
lambda: self.name_e.setText(get_new_wallet_name(datadir_wallet_folder))) # FIXME get_new_wallet_name might raise
|
||||
self.name_e.textChanged.connect(on_filename)
|
||||
self.name_e.setText(os.path.basename(path))
|
||||
self.name_e.setText(relative_path(path))
|
||||
|
||||
def apply(self):
|
||||
if self.wallet_exists:
|
||||
# use full path
|
||||
path = self.wizard._path
|
||||
wallet_folder = os.path.dirname(path)
|
||||
wallet_folder = self.wizard.config.get_datadir_wallet_path()
|
||||
self.wizard_data['wallet_name'] = os.path.join(wallet_folder, self.name_e.text())
|
||||
else:
|
||||
self.wizard_data['wallet_name'] = self.name_e.text()
|
||||
|
||||
@@ -445,6 +445,7 @@ class SimpleConfig(Logger):
|
||||
|
||||
new_path = self.get_fallback_wallet_path()
|
||||
|
||||
# TODO: this can be removed by now
|
||||
# default path in pre 1.9 versions
|
||||
old_path = os.path.join(self.path, "electrum.dat")
|
||||
if os.path.exists(old_path) and not os.path.exists(new_path):
|
||||
@@ -452,12 +453,14 @@ class SimpleConfig(Logger):
|
||||
|
||||
return new_path
|
||||
|
||||
def get_fallback_wallet_path(self):
|
||||
def get_datadir_wallet_path(self):
|
||||
util.assert_datadir_available(self.path)
|
||||
dirpath = os.path.join(self.path, "wallets")
|
||||
make_dir(dirpath, allow_symlink=False)
|
||||
path = os.path.join(self.path, "wallets", "default_wallet")
|
||||
return path
|
||||
return dirpath
|
||||
|
||||
def get_fallback_wallet_path(self):
|
||||
return os.path.join(self.get_datadir_wallet_path(), "default_wallet")
|
||||
|
||||
def remove_from_recently_open(self, filename):
|
||||
recent = self.RECENTLY_OPEN_WALLET_FILES or []
|
||||
|
||||
Reference in New Issue
Block a user