From 92b39c9e0c6033cff0535393f7a089312f0b15a9 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Thu, 1 Nov 2018 10:42:04 -0400 Subject: [PATCH] Fix cli creating /tmp/gpg-sig dir unexpectedly 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 --- lftools/cli/sign.py | 9 +++++++-- releasenotes/notes/unnecessary-sign-dir-35677f94e948d2a8.yaml | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/unnecessary-sign-dir-35677f94e948d2a8.yaml diff --git a/lftools/cli/sign.py b/lftools/cli/sign.py index 9f5c4911..256d13ce 100644 --- a/lftools/cli/sign.py +++ b/lftools/cli/sign.py @@ -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 index 00000000..d44a2782 --- /dev/null +++ b/releasenotes/notes/unnecessary-sign-dir-35677f94e948d2a8.yaml @@ -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. -- 2.16.6