From 4742ffd8582b5c60fd1a1a918370d13aca278c54 Mon Sep 17 00:00:00 2001 From: KnugiHK <24708955+KnugiHK@users.noreply.github.com> Date: Thu, 19 Jun 2025 00:10:31 +0800 Subject: [PATCH] Handle a permission error on macOS #158 Although this does not fix the issue, when the error occurs, it will provide more information to users --- Whatsapp_Chat_Exporter/ios_media_handler.py | 28 ++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Whatsapp_Chat_Exporter/ios_media_handler.py b/Whatsapp_Chat_Exporter/ios_media_handler.py index a010c92..44575e0 100644 --- a/Whatsapp_Chat_Exporter/ios_media_handler.py +++ b/Whatsapp_Chat_Exporter/ios_media_handler.py @@ -5,7 +5,7 @@ import shutil import sqlite3 import os import getpass -from sys import exit +from sys import exit, platform as osname from Whatsapp_Chat_Exporter.utility import CLEAR_LINE, WhatsAppIdentifier from Whatsapp_Chat_Exporter.bplist import BPListReader try: @@ -46,15 +46,25 @@ class BackupExtractor: Returns: bool: True if encrypted, False otherwise. """ - with sqlite3.connect(os.path.join(self.base_dir, "Manifest.db")) as db: - c = db.cursor() - try: - c.execute("SELECT count() FROM Files") - c.fetchone() # Execute and fetch to trigger potential errors - except (sqlite3.OperationalError, sqlite3.DatabaseError): - return True + try: + with sqlite3.connect(os.path.join(self.base_dir, "Manifest.db")) as db: + c = db.cursor() + try: + c.execute("SELECT count() FROM Files") + c.fetchone() # Execute and fetch to trigger potential errors + except (sqlite3.OperationalError, sqlite3.DatabaseError): + return True + else: + return False + except sqlite3.DatabaseError as e: + if e == "authorization denied" and osname == "darwin": + logger.error( + "You don't have permission to access the backup database. Please" + "check your permissions or try moving the backup to somewhere else." + ) + exit(8) else: - return False + raise e def _extract_encrypted_backup(self): """