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.
This commit is contained in:
Levente Polyak 2021-10-24 15:06:38 +02:00
parent 58307c629d
commit 94c3b4c8e9
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
2 changed files with 15 additions and 12 deletions

View File

@ -133,13 +133,15 @@ def main() -> None:
)
)
elif "export" == args.subcommand:
print(
export(
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:

View File

@ -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)