Fix cli creating /tmp/gpg-sig dir unexpectedly 70/13270/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 1 Nov 2018 14:42:04 +0000 (10:42 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 1 Nov 2018 14:45:47 +0000 (10:45 -0400)
Simply calling the cli always creates 2 directories named
/tmp/gpg-signatures.* and flooding /tmp with unnecessary directories.

This patch resolves these unexpected directory creations by declaring
these tmpdirs in the code rather than the function definition to avoid
this issue.

Change-Id: I3762854fea187082bb8f459ca062e02c1f4eb43f
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
lftools/cli/sign.py
releasenotes/notes/unnecessary-sign-dir-35677f94e948d2a8.yaml [new file with mode: 0644]

index 9f5c491..256d13c 100644 (file)
@@ -39,7 +39,7 @@ def directory(ctx, directory):
 @click.argument('nexus-repo-url')
 @click.option(
     '-d', '--sign-dir', type=str,
-    default=tempfile.mkdtemp(prefix='gpg-signatures.'),
+    default=None,
     help='Local directory to clone repository. (default /tmp/gpg-signatures.*)')
 @click.option(
     '-w', '--sign-with', type=str, default='gpg',
@@ -47,6 +47,8 @@ def directory(ctx, directory):
 @click.pass_context
 def nexus(ctx, sign_dir, sign_with, nexus_repo_url):
     """Fetch and GPG or Sigul sign a Nexus repo."""
+    if not sign_dir:
+        sign_dir = tempfile.mkdtemp(prefix='gpg-signatures.')
     status = subprocess.call(['sign', 'nexus', '-d', sign_dir, '-w', sign_with, nexus_repo_url])
     sys.exit(status)
 
@@ -66,7 +68,7 @@ def sigul(ctx, directory):
 @click.argument('staging-profile-id', envvar='STAGING_PROFILE_ID')
 @click.option(
     '-d', '--sign-dir', type=str,
-    default=tempfile.mkdtemp(prefix='gpg-signatures.'),
+    default=None,
     help='Local directory to clone repository. (default /tmp/gpg-signatures.*)')
 @click.option(
     '-r', '--root-domain', type=str, default='org',
@@ -91,6 +93,9 @@ def deploy_nexus(ctx, nexus_url, nexus_repo, staging_profile_id, sign_dir, sign_
     nexus_url = nexus_url.rstrip('/')
     nexus_repo_url = "{}/content/repositories/{}/{}".format(nexus_url, nexus_repo, root_domain)
 
+    if not sign_dir:
+        sign_dir = tempfile.mkdtemp(prefix='gpg-signatures.')
+
     status = subprocess.call(['sign', 'nexus', '-d', sign_dir, '-w', sign_with, nexus_repo_url])
     if status:
         sys.exit(status)
diff --git a/releasenotes/notes/unnecessary-sign-dir-35677f94e948d2a8.yaml b/releasenotes/notes/unnecessary-sign-dir-35677f94e948d2a8.yaml
new file mode 100644 (file)
index 0000000..d44a278
--- /dev/null
@@ -0,0 +1,6 @@
+---
+fixes:
+  - |
+    Running the lftools CLI was unexpectedly creating unnecessary
+    gpg-signatures directories in the /tmp directory and not cleaning
+    them up.