diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index dde84a97c9..182ded099f 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -14,7 +14,7 @@ for a particular device. import os, time, json, shutil from itertools import cycle -from calibre.constants import numeric_version +from calibre.constants import numeric_version, ismacos from calibre import prints, isbytestring, fsync from calibre.constants import filesystem_encoding, DEBUG from calibre.devices.usbms.cli import CLI @@ -147,17 +147,30 @@ class USBMS(CLI, Device): def get_device_information(self, end_session=True): self.report_progress(1.0, _('Get device information...')) self.driveinfo = {} + + def raise_os_error(e): + raise OSError(_('Failed to access files in the main memory of' + ' your device. You should contact the device' + ' manufacturer for support. Common fixes are:' + ' try a different USB cable/USB port on your computer.' + ' If you device has a "Reset to factory defaults" type' + ' of setting somewhere, use it. Underlying error: %s') + % e) from e + if self._main_prefix is not None: try: self.driveinfo['main'] = self._update_driveinfo_file(self._main_prefix, 'main') + except PermissionError as e: + if ismacos: + raise PermissionError(_( + 'Permission was denied by macOS trying to access files in the main memory of' + ' your device. You will need to grant permission explicitly by looking under' + ' System Preferences > Security and Privacy > Privacy > Files and Folders.' + ' Underlying error: %s' + ) % e) from e + raise_os_error(e) except OSError as e: - raise OSError(_('Failed to access files in the main memory of' - ' your device. You should contact the device' - ' manufacturer for support. Common fixes are:' - ' try a different USB cable/USB port on your computer.' - ' If you device has a "Reset to factory defaults" type' - ' of setting somewhere, use it. Underlying error: %s') - % e) + raise_os_error(e) try: if self._card_a_prefix is not None: self.driveinfo['A'] = self._update_driveinfo_file(self._card_a_prefix, 'A')