From da775954c0a17522a4431780365ff9a64459f8b2 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 12 Dec 2023 01:34:46 +0000 Subject: [PATCH] qt wizard: fix wallets directory relative paths on Windows follow-up https://github.com/spesmilo/electrum/pull/8651 We cannot do direct comparison of path-like strings without normalisation. E.g. ``` relative_path() cp1. path='c:\\users\\user\\appdata\\roaming\\electrum\\wallets\\9dk', wallets=C:\Users\User\AppData\Roaming\Electrum\wallets relative_path() cp2. commonpath='c:\\users\\user\\appdata\\roaming\\electrum\\wallets' relative_path() cp3. new_path='9dk' ``` --- electrum/gui/qt/wizard/wallet.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/electrum/gui/qt/wizard/wallet.py b/electrum/gui/qt/wizard/wallet.py index 84e34f6b9..29c845845 100644 --- a/electrum/gui/qt/wizard/wallet.py +++ b/electrum/gui/qt/wizard/wallet.py @@ -16,6 +16,7 @@ from electrum.keystore import bip44_derivation, bip39_to_seed, purpose48_derivat from electrum.plugin import run_hook, HardwarePluginLibraryUnavailable from electrum.storage import StorageReadWriteError from electrum.util import WalletFileException, get_new_wallet_name, UserFacingException, InvalidPassword +from electrum.util import is_subpath from electrum.wallet import wallet_types from .wizard import QEAbstractWizard, WizardComponent from electrum.logging import get_logger, Logger @@ -303,9 +304,9 @@ class WCWalletName(WizardComponent, Logger): def relative_path(path): new_path = path try: - commonpath = os.path.commonpath([path, datadir_wallet_folder]) - if commonpath == datadir_wallet_folder: + if is_subpath(path, datadir_wallet_folder): # below datadir_wallet_path, make relative + commonpath = os.path.commonpath([path, datadir_wallet_folder]) new_path = os.path.relpath(path, commonpath) except ValueError: pass