From 70e39102b000ae51e63ccbc77135fbdbcb778d72 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Sun, 11 Oct 2020 14:49:22 -0700 Subject: [PATCH] ensure only one hyperglass directory exists --- hyperglass/util/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hyperglass/util/__init__.py b/hyperglass/util/__init__.py index 36e2355..ede96a1 100644 --- a/hyperglass/util/__init__.py +++ b/hyperglass/util/__init__.py @@ -692,6 +692,13 @@ def set_app_path(required: bool = False) -> Path: config_paths = (Path.home() / "hyperglass", Path("/etc/hyperglass/")) + # Ensure only one app directory exists to reduce confusion. + if all((p.exists() for p in config_paths)): + raise RuntimeError( + "Both '{}' and '{}' exist. ".format(*(p.as_posix() for p in config_paths)) + + "Please choose only one configuration directory and delete the other." + ) + for path in config_paths: try: if path.exists(): @@ -708,9 +715,9 @@ def set_app_path(required: bool = False) -> Path: # Only raise an error if required is True raise RuntimeError( """ - No configuration directories were determined to both exist and be readable - by hyperglass. hyperglass is running as user '{un}' (UID '{uid}'), and tried - to access the following directories: +No configuration directories were determined to both exist and be readable +by hyperglass. hyperglass is running as user '{un}' (UID '{uid}'), and tried +to access the following directories: {dir}""".format( un=getuser(), uid=os.getuid(),