From 1288f8ca5308f0ba97b35ed5bd30213e58211e5d Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Tue, 10 Aug 2021 21:55:36 -0400 Subject: [PATCH] handle error cases better --- mvt/ios/cli.py | 5 ++++- mvt/ios/decrypt.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mvt/ios/cli.py b/mvt/ios/cli.py index c98d9f7..9075626 100644 --- a/mvt/ios/cli.py +++ b/mvt/ios/cli.py @@ -53,7 +53,8 @@ def cli(): help="File containing raw encryption key to use to decrypt the backup", mutually_exclusive=["password"]) @click.argument("BACKUP_PATH", type=click.Path(exists=True)) -def decrypt_backup(destination, password, key_file, backup_path): +@click.pass_context +def decrypt_backup(ctx, destination, password, key_file, backup_path): backup = DecryptBackup(backup_path, destination) if key_file: @@ -75,6 +76,8 @@ def decrypt_backup(destination, password, key_file, backup_path): sekrit = Prompt.ask("Enter backup password", password=True) backup.decrypt_with_password(sekrit) + if not backup.can_process(): + ctx.exit(1) backup.process_backup() diff --git a/mvt/ios/decrypt.py b/mvt/ios/decrypt.py index fe50af5..51c7ff2 100644 --- a/mvt/ios/decrypt.py +++ b/mvt/ios/decrypt.py @@ -28,6 +28,9 @@ class DecryptBackup: self._backup = None self._decryption_key = None + def can_process(self) -> bool: + return self._backup is not None + def process_backup(self): if not os.path.exists(self.dest_path): os.makedirs(self.dest_path)