From 7bde152ed331c179dfca0508e5267e17db09d388 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 25 Sep 2023 10:27:23 +0530 Subject: [PATCH] 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) --- src/calibre/db/backend.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 86648ed6c3..34bdd469e8 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -2040,13 +2040,14 @@ class DB: for base in ('b', 'f'): base = os.path.join(self.trash_dir, base) for x in os.scandir(base): - try: - st = x.stat(follow_symlinks=False) - mtime = st.st_mtime - except OSError: - mtime = 0 - if mtime + expire_age_in_seconds <= now or expire_age_in_seconds <= 0: - removals.append(x.path) + if x.is_dir(follow_symlinks=False): + try: + st = x.stat(follow_symlinks=False) + mtime = st.st_mtime + except OSError: + mtime = 0 + if mtime + expire_age_in_seconds <= now or expire_age_in_seconds <= 0: + removals.append(x.path) for x in removals: try: rmtree_with_retry(x)