Dont expose the trash book dir when listing entries

This commit is contained in:
Kovid Goyal 2023-04-11 19:52:05 +05:30
parent f2f49c9d8e
commit fff9686192
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 13 additions and 7 deletions

View File

@ -69,7 +69,7 @@ class TrashEntry:
book_id: int
title: str
author: str
book_dir: str
cover_path: str
mtime: float
formats: Sequence[str] = ()
@ -1968,7 +1968,7 @@ class DB:
except Exception:
continue
opf = OPF(os.path.join(x.path, 'metadata.opf'), basedir=x.path)
books.append(TrashEntry(book_id, opf.title or unknown, (opf.authors or au)[0], x.path, mtime))
books.append(TrashEntry(book_id, opf.title or unknown, (opf.authors or au)[0], os.path.join(x.path, COVER_FILE_NAME), mtime))
base = os.path.join(self.trash_dir, 'f')
um = {'title': unknown, 'authors': au}
for x in os.scandir(base):
@ -1988,7 +1988,7 @@ class DB:
else:
formats.add(f.name.upper())
if formats:
files.append(TrashEntry(book_id, metadata.get('title') or unknown, (metadata.get('authors') or au)[0], x.path, mtime, tuple(formats)))
files.append(TrashEntry(book_id, metadata.get('title') or unknown, (metadata.get('authors') or au)[0], '', mtime, tuple(formats)))
return books, files
def remove_books(self, path_map, permanent=False):

View File

@ -2665,7 +2665,13 @@ class Cache:
@read_api
def list_trash_entries(self):
return self.backend.list_trash_entries()
books, formats = self.backend.list_trash_entries()
ff = []
for e in formats:
if self._has_id(e.book_id):
ff.append(e)
e.cover_path = self.format_abspath(e.book_id, '__COVER_INTERNAL__')
return books, formats
@write_api
def move_book_from_trash(self, book_id):

View File

@ -281,11 +281,11 @@ class AddRemoveTest(BaseTest):
self.assertEqual(len(b), 1)
self.assertEqual(len(f), 0)
self.assertEqual(b[0].title, title)
self.assertTrue(os.path.exists(os.path.join(b[0].book_dir, 'metadata.opf')))
self.assertTrue(os.path.exists(b[0].cover_path))
cache.backend.expire_old_trash(1000)
self.assertTrue(os.path.exists(os.path.join(b[0].book_dir, 'metadata.opf')))
self.assertTrue(os.path.exists(b[0].cover_path))
cache.backend.expire_old_trash(0)
self.assertFalse(os.path.exists(os.path.join(b[0].book_dir, 'metadata.opf')))
self.assertFalse(os.path.exists(b[0].cover_path))
# test restoring of books
cache = self.init_cache(cl2)