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,15 +133,17 @@ def main() -> None:
) )
) )
elif "export" == args.subcommand: elif "export" == args.subcommand:
print( result = export(
export( working_dir=working_dir,
working_dir=working_dir, keyring_root=keyring_root,
keyring_root=keyring_root, sources=args.source,
sources=args.source, output=args.output,
output=args.output,
),
end="",
) )
if result:
print(
result,
end="",
)
elif "build" == args.subcommand: elif "build" == args.subcommand:
build( build(
working_dir=working_dir, working_dir=working_dir,

View File

@ -62,8 +62,6 @@ def get_cert_paths(paths: Iterable[Path]) -> Set[Path]:
visit: List[Path] = list(paths) visit: List[Path] = list(paths)
while visit: while visit:
path = visit.pop() path = visit.pop()
if not path.exists():
continue
# this level contains a certificate, abort depth search # this level contains a certificate, abort depth search
if list(path.glob("*.asc")): if list(path.glob("*.asc")):
cert_paths.add(path) cert_paths.add(path)
@ -580,7 +578,7 @@ def convert(
get_fingerprints( get_fingerprints(
working_dir=working_dir, working_dir=working_dir,
sources=source, sources=source,
paths=[keyring_root], paths=[keyring_root] if keyring_root.exists() else [],
).keys() ).keys()
) )
@ -832,7 +830,7 @@ def export(
keyring_root: Path, keyring_root: Path,
sources: Optional[List[Path]] = None, sources: Optional[List[Path]] = None,
output: Optional[Path] = None, output: Optional[Path] = None,
) -> str: ) -> Optional[str]:
"""Export all provided PGP packet files to a single output file """Export all provided PGP packet files to a single output file
If sources contains directories, any .asc files below them are considered. If sources contains directories, any .asc files below them are considered.
@ -876,6 +874,9 @@ def export(
) )
certificates.append(output_path) certificates.append(output_path)
if not certificates:
return None
return keyring_merge(certificates, output, force=True) return keyring_merge(certificates, output, force=True)