From ae23f146d1063a3fac7195d8caffd79b6c0004d0 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 22 Mar 2019 09:36:13 +0000 Subject: [PATCH] Use the user's full email address (not just the username part) as the basis for the storage directory name.. Fixes #3887 --- docs/en_US/release_notes_4_4.rst | 22 +++++++++++++++++++++- web/pgadmin/utils/paths.py | 20 ++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/en_US/release_notes_4_4.rst b/docs/en_US/release_notes_4_4.rst index c35b0b7ae..5a99c6a78 100644 --- a/docs/en_US/release_notes_4_4.rst +++ b/docs/en_US/release_notes_4_4.rst @@ -5,7 +5,26 @@ Version 4.4 Release date: 2019-04-04 This release contains a number of new features and fixes reported since the -release of pgAdmin4 4.3 +release of pgAdmin4 4.3. + +.. warning:: This release includes a bug fix + (`Bug #3887 `_) which will + rename the per-user storage directories for existing users when running in + server mode. Previously, saved SQL queries were stored under the + *STORAGE_DIR* in a sub-directory named after the username part of the user's + email address. From this version onwards, the full email address is used, + with the @ replaced with an underscore. For example, in v.4.3 with + *STORAGE_DIR* set to */var/lib/pgadmin4* user files may be stored in: + + .. code-block:: bash + + /var/lib/pgadmin4/storage/username/ + + With the fix, that directory will be renamed (or created for new users) as: + + .. code-block:: bash + + /var/lib/pgadmin4/storage/username_example.com/ Features ******** @@ -20,6 +39,7 @@ Bug fixes | `Bug #1269 `_ - Fix naming inconsistency for the column and FTS parser modules. | `Bug #3104 `_ - Improve a couple of German translations. +| `Bug #3887 `_ - Use the user's full email address (not just the username part) as the basis for the storage directory name. | `Bug #3968 `_ - Update wcDocker to fix the issue where the Scratch Pad grows in size if the results panel is resized. | `Bug #3995 `_ - Avoid 'bogus varno' message from Postgres when viewing the SQL for a table with triggers. | `Bug #4019 `_ - Update all Python and JavaScript dependencies. diff --git a/web/pgadmin/utils/paths.py b/web/pgadmin/utils/paths.py index 9b96bf74c..8f188474f 100644 --- a/web/pgadmin/utils/paths.py +++ b/web/pgadmin/utils/paths.py @@ -11,7 +11,7 @@ import os -from flask import url_for +from flask import current_app, url_for from flask_security import current_user, login_required @@ -37,12 +37,28 @@ def get_storage_directory(): if len(username) == 0 or username[0].isdigit(): username = 'pga_user_' + username - storage_dir = os.path.join( + # Figure out the old-style storage directory name + old_storage_dir = os.path.join( storage_dir.decode('utf-8') if hasattr(storage_dir, 'decode') else storage_dir, username ) + # Figure out the new style storage directory name + storage_dir = os.path.join( + storage_dir.decode('utf-8') if hasattr(storage_dir, 'decode') + else storage_dir, + current_user.email.replace('@', '_') + ) + + # Rename an old-style storage directory, if the new style doesn't exist + if os.path.exists(old_storage_dir) and not os.path.exists(storage_dir): + current_app.logger.warning( + 'Renaming storage directory %s to %s.', + old_storage_dir, storage_dir + ) + os.rename(old_storage_dir, storage_dir) + if not os.path.exists(storage_dir): os.makedirs(storage_dir, int('700', 8))