From 2f9ef0ef1d72be64f080621594a38a86f2c40a42 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Wed, 20 Oct 2021 02:16:10 +0200 Subject: [PATCH] feature(keyringctl): keep filename if keyring split yields one keyring Instead of always returning an artificial name try to preserve the keyring filename if the split only yields a single certificate. --- keyringctl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/keyringctl b/keyringctl index 993ff95..32f24a0 100755 --- a/keyringctl +++ b/keyringctl @@ -611,7 +611,8 @@ def packet_dump_field(packet: Path, field: str) -> str: def keyring_split(working_dir: Path, keyring: Path) -> Iterable[Path]: """Split a file containing a PGP keyring into separate certificate files - The file is split using sq + The original keyring filename is preserved if the split only yields a single certificate. + The file is split using sq. Parameters ---------- @@ -630,7 +631,13 @@ def keyring_split(working_dir: Path, keyring: Path) -> Iterable[Path]: with cwd(keyring_dir): system(["sq", "keyring", "split", "--prefix", "", str(keyring)]) - return natural_sort_path(keyring_dir.iterdir()) + + keyrings: List[Path] = list(natural_sort_path(keyring_dir.iterdir())) + + if 1 == len(keyrings): + keyrings[0] = keyrings[0].rename(keyrings[0].parent / keyring.name) + + return keyrings def packet_split(working_dir: Path, certificate: Path) -> Iterable[Path]: