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.
This commit is contained in:
Levente Polyak 2021-10-20 02:16:10 +02:00
parent b91e8b983c
commit 2f9ef0ef1d
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8

View File

@ -611,7 +611,8 @@ def packet_dump_field(packet: Path, field: str) -> str:
def keyring_split(working_dir: Path, keyring: Path) -> Iterable[Path]: def keyring_split(working_dir: Path, keyring: Path) -> Iterable[Path]:
"""Split a file containing a PGP keyring into separate certificate files """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 Parameters
---------- ----------
@ -630,7 +631,13 @@ def keyring_split(working_dir: Path, keyring: Path) -> Iterable[Path]:
with cwd(keyring_dir): with cwd(keyring_dir):
system(["sq", "keyring", "split", "--prefix", "", str(keyring)]) 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]: def packet_split(working_dir: Path, certificate: Path) -> Iterable[Path]: