[gnome-keysign: 7/9] gpgmeh: Let gpgconf determin the homedir



commit 3437555304fc0875ab68863aa598bb71952f2ba3
Author: Tobias Mueller <muelli cryptobitch de>
Date:   Mon Feb 12 21:39:19 2018 +0100

    gpgmeh: Let gpgconf determin the homedir
    
    gpgconf does the right thing, i.e. respecting the GNUPGHOME environment
    variable, so we can as well let it do its job.
    
    I got into trouble when using a second instance with such an environment
    variable. The logic would revert my efforts by manually overwriting the
    homedir with my actual homedir. That is not desireable, of course.
    This change makes it work as expected.

 keysign/gpgmeh.py | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
---
diff --git a/keysign/gpgmeh.py b/keysign/gpgmeh.py
index 43a595b..bc3d3cc 100644
--- a/keysign/gpgmeh.py
+++ b/keysign/gpgmeh.py
@@ -239,12 +239,12 @@ class TempContext(DirectoryContext):
             log.exception("During cleanup of %r", self.homedir)
 
 def get_agent_socket_path_for_homedir(homedir):
-       cmd = ["gpgconf",
-              "--homedir", homedir,
-              "--list-dirs", "agent-socket"]
-       path = check_output(cmd).strip()
-       log.info("Path for %r: %r", homedir, path)
-       return path
+    homedir_cmd = ["--homedir", homedir] if homedir else []
+    cmd = ["gpgconf"] + homedir_cmd + \
+          ["--list-dirs", "agent-socket"]
+    path = check_output(cmd).strip()
+    log.info("Path for %r: %r", homedir, path)
+    return path
 
 
 class TempContextWithAgent(TempContext):
@@ -256,12 +256,7 @@ class TempContextWithAgent(TempContext):
         assert (len(list(self.keylist(secret=True))) == 0)
 
 
-        if oldctx:
-            old_homedir = oldctx.engine_info.home_dir
-            if not old_homedir:
-                old_homedir = os.path.join(os.path.expanduser("~"), ".gnupg")
-        else:
-            old_homedir = os.path.join(os.path.expanduser("~"), ".gnupg")
+        old_homedir = oldctx.engine_info.home_dir if oldctx else None
 
         log.info("Old homedir: %r", old_homedir)
         old_agent_path = get_agent_socket_path_for_homedir(old_homedir)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]