Kobo driver: Delete empty directories in root

These accumulate over time if user deletes books on device rather than
via calibre.
This commit is contained in:
Kovid Goyal 2025-02-24 19:40:27 +05:30
parent e40228cb84
commit f637014ad1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -17,7 +17,7 @@ import os
import re import re
import shutil import shutil
import time import time
from contextlib import closing from contextlib import closing, suppress
from datetime import datetime from datetime import datetime
from calibre import fsync, prints, strftime from calibre import fsync, prints, strftime
@ -1631,6 +1631,17 @@ class KOBOTOUCH(KOBO):
self.set_device_name() self.set_device_name()
return super().get_device_information(end_session) return super().get_device_information(end_session)
def post_open_callback(self):
# delete empty directories in root they get left behind when deleting
# books on device.
for prefix in (self._main_prefix, self._card_a_prefix, self._card_b_prefix):
if prefix:
with suppress(OSError):
for de in os.scandir(prefix):
if not de.name.startswith('.') and de.is_dir():
with suppress(OSError):
os.rmdir(de.path)
def open_linux(self): def open_linux(self):
super().open_linux() super().open_linux()