mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Better error message for permission denied when accessing device files on macOS
This commit is contained in:
parent
21e76f7d73
commit
37c35a1ec4
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user