Fix errors caused by .DS_Store files inserted into the .caltrash directory on macOS if the user happens to open .caltrash in Finder. Fixes #2037237 [NotADirectoryError when merging books on MacOS](https://bugs.launchpad.net/calibre/+bug/2037237)

This commit is contained in:
Kovid Goyal 2023-09-25 10:27:23 +05:30
parent 3d045fb230
commit 7bde152ed3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2040,13 +2040,14 @@ class DB:
for base in ('b', 'f'): for base in ('b', 'f'):
base = os.path.join(self.trash_dir, base) base = os.path.join(self.trash_dir, base)
for x in os.scandir(base): for x in os.scandir(base):
try: if x.is_dir(follow_symlinks=False):
st = x.stat(follow_symlinks=False) try:
mtime = st.st_mtime st = x.stat(follow_symlinks=False)
except OSError: mtime = st.st_mtime
mtime = 0 except OSError:
if mtime + expire_age_in_seconds <= now or expire_age_in_seconds <= 0: mtime = 0
removals.append(x.path) if mtime + expire_age_in_seconds <= now or expire_age_in_seconds <= 0:
removals.append(x.path)
for x in removals: for x in removals:
try: try:
rmtree_with_retry(x) rmtree_with_retry(x)