|
14 | 14 | from collections import defaultdict |
15 | 15 | from operator import attrgetter |
16 | 16 |
|
| 17 | +from pathlib import Path |
17 | 18 | from flask import Blueprint, current_app, url_for |
18 | 19 | from flask_babel import gettext |
19 | 20 | from flask_security import current_user, login_required |
20 | 21 | from flask_security.utils import get_post_login_redirect, \ |
21 | 22 | get_post_logout_redirect |
22 | 23 | from threading import Lock |
23 | | - |
| 24 | +import config |
24 | 25 | from .paths import get_storage_directory |
25 | 26 | from .preferences import Preferences |
26 | 27 | from pgadmin.utils.constants import UTILITIES_ARRAY, USER_NOT_FOUND, \ |
@@ -308,11 +309,18 @@ def does_utility_exist(file): |
308 | 309 | :return: |
309 | 310 | """ |
310 | 311 | error_msg = None |
| 312 | + |
311 | 313 | if file is None: |
312 | 314 | error_msg = gettext("Utility file not found. Please correct the Binary" |
313 | 315 | " Path in the Preferences dialog") |
314 | 316 | return error_msg |
315 | 317 |
|
| 318 | + if Path(config.STORAGE_DIR) == Path(file) or \ |
| 319 | + Path(config.STORAGE_DIR) in Path(file).parents: |
| 320 | + error_msg = gettext("Please correct the Binary Path in the Preferences" |
| 321 | + " dialog. pgAdmin storage directory can not be a" |
| 322 | + " utility binary directory.") |
| 323 | + |
316 | 324 | if not os.path.exists(file): |
317 | 325 | error_msg = gettext("'%s' file not found. Please correct the Binary" |
318 | 326 | " Path in the Preferences dialog" % file) |
@@ -364,7 +372,8 @@ def get_binary_path_versions(binary_path: str) -> dict: |
364 | 372 |
|
365 | 373 |
|
366 | 374 | def set_binary_path(binary_path, bin_paths, server_type, |
367 | | - version_number=None, set_as_default=False): |
| 375 | + version_number=None, set_as_default=False, |
| 376 | + is_fixed_path=False): |
368 | 377 | """ |
369 | 378 | This function is used to iterate through the utilities and set the |
370 | 379 | default binary path. |
@@ -394,6 +403,8 @@ def set_binary_path(binary_path, bin_paths, server_type, |
394 | 403 | if path_with_dir is not None else binary_path |
395 | 404 | if set_as_default: |
396 | 405 | path['isDefault'] = True |
| 406 | + # Whether the fixed path in the config file exists or not |
| 407 | + path['isFixed'] = is_fixed_path |
397 | 408 | break |
398 | 409 | break |
399 | 410 | except Exception: |
|
0 commit comments