From 6a34d93ce2388feeae320ab1c614bc48ad2d4b31 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 23 Mar 2022 20:06:42 +0100 Subject: [PATCH] "--portable": more consistent behaviour The old and new behaviour is as follows: 1. "pyinstaller" case: portable `.exe`, other `.exe`s with `--portable`, and `.dmg` with `--portable` - uses `$PWD` - note that when you double-click the portable `.exe` on Windows, `$PWD` is set to the parent folder, i.e. the datadir gets put next to the `.exe` 2. appimage `--portable` - was broken (see https://github.com/spesmilo/electrum/issues/5551) - (CHANGED NOW to) uses `$PWD` 3. git clone - next to `run_electrum` 4. unpacking `tar.gz` and running locally from it - next to `run_electrum` 5. `pip install *.tar.gz`, and calling "electrum --portable" from terminal - used python's user script directory - `~/.local/bin/electrum_data` - `$VIRTUAL_ENV/bin/electrum_data` - (CHANGED NOW to) uses `$PWD` That is, we now almost always put the datadir in `$PWD`, except for the local source case, where we put it next to `run_electrum`. The "appimage" case (2) is now fixed. The only breaking change is re case 5 which previously behaved completely unintuitively and most likely not in a useful way. closes https://github.com/spesmilo/electrum/issues/7732 fixes https://github.com/spesmilo/electrum/issues/5551 --- run_electrum | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/run_electrum b/run_electrum index b610f341d541..d6a0daf2ef51 100755 --- a/run_electrum +++ b/run_electrum @@ -338,10 +338,17 @@ def main(): config_options['portable'] = True if config_options.get('portable'): - if is_pyinstaller: - datadir = os.path.join(os.path.realpath(cwd), 'electrum_data') - else: + if is_local: + # running from git clone or local source: put datadir next to main script datadir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'electrum_data') + else: + # Running a binary or installed source. The most generic but still reasonable thing + # is to use the current working directory. (see #7732) + # note: The main script is often unpacked to a temporary directory from a bundled executable, + # and we don't want to put the datadir inside a temp dir. + # note: Re the portable .exe on Windows, when the user double-clicks it, CWD gets set + # to the parent dir, i.e. we will put the datadir next to the exe. + datadir = os.path.join(os.path.realpath(cwd), 'electrum_data') config_options['electrum_path'] = datadir if not config_options.get('verbosity'):