From 94c3b4c8e99aa0161eaf327c6acc8a1d83f61f16 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sun, 24 Oct 2021 15:06:38 +0200 Subject: [PATCH] fix(keyrinctl): yield file not found errors instead of blocking on stdin Handle missing or wrong certificate paths in a way that does not lead to a blocking command by reading from stdin. Instead throw either file not found errors or expect optional outputs. --- libkeyringctl/cli.py | 18 ++++++++++-------- libkeyringctl/keyring.py | 9 +++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libkeyringctl/cli.py b/libkeyringctl/cli.py index 881c666..5fa9087 100644 --- a/libkeyringctl/cli.py +++ b/libkeyringctl/cli.py @@ -133,15 +133,17 @@ def main() -> None: ) ) elif "export" == args.subcommand: - print( - export( - working_dir=working_dir, - keyring_root=keyring_root, - sources=args.source, - output=args.output, - ), - end="", + result = export( + working_dir=working_dir, + keyring_root=keyring_root, + sources=args.source, + output=args.output, ) + if result: + print( + result, + end="", + ) elif "build" == args.subcommand: build( working_dir=working_dir, diff --git a/libkeyringctl/keyring.py b/libkeyringctl/keyring.py index 07f9768..5c2128a 100644 --- a/libkeyringctl/keyring.py +++ b/libkeyringctl/keyring.py @@ -62,8 +62,6 @@ def get_cert_paths(paths: Iterable[Path]) -> Set[Path]: visit: List[Path] = list(paths) while visit: path = visit.pop() - if not path.exists(): - continue # this level contains a certificate, abort depth search if list(path.glob("*.asc")): cert_paths.add(path) @@ -580,7 +578,7 @@ def convert( get_fingerprints( working_dir=working_dir, sources=source, - paths=[keyring_root], + paths=[keyring_root] if keyring_root.exists() else [], ).keys() ) @@ -832,7 +830,7 @@ def export( keyring_root: Path, sources: Optional[List[Path]] = None, output: Optional[Path] = None, -) -> str: +) -> Optional[str]: """Export all provided PGP packet files to a single output file If sources contains directories, any .asc files below them are considered. @@ -876,6 +874,9 @@ def export( ) certificates.append(output_path) + if not certificates: + return None + return keyring_merge(certificates, output, force=True)