diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index d349ce46d8..0af8b8071d 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -1015,6 +1015,13 @@ class Device(DeviceConfig, DevicePlugin): return path + def sanitize_callback(self, path): + ''' + Callback to allow individual device drivers to override the path sanitization + used by :meth:`create_upload_path`. + ''' + return sanitize(path) + def filename_callback(self, default, mi): ''' Callback to allow drivers to change the default file name @@ -1044,7 +1051,7 @@ class Device(DeviceConfig, DevicePlugin): def create_upload_path(self, path, mdata, fname, create_dirs=True): from calibre.devices.utils import create_upload_path settings = self.settings() - filepath = create_upload_path(mdata, fname, self.save_template(), sanitize, + filepath = create_upload_path(mdata, fname, self.save_template(), self.sanitize_callback, prefix_path=os.path.abspath(path), maxlen=self.MAX_PATH_LEN, use_subdirs = self.SUPPORTS_SUB_DIRS and settings.use_subdirs, diff --git a/src/calibre/devices/utils.py b/src/calibre/devices/utils.py index 114e7e4e13..ded1afa8ef 100644 --- a/src/calibre/devices/utils.py +++ b/src/calibre/devices/utils.py @@ -99,7 +99,8 @@ def create_upload_path(mdata, fname, template, sanitize, app_id = str(getattr(mdata, 'application_id', '')) id_ = mdata.get('id', fname) extra_components = get_components(template, mdata, id_, - timefmt=opts.send_timefmt, length=maxlen-len(app_id)-1) + timefmt=opts.send_timefmt, length=maxlen-len(app_id)-1, + sanitize_func=sanitize) if not extra_components: extra_components.append(sanitize(filename_callback(fname, mdata)))