mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont expose the trash book dir when listing entries
This commit is contained in:
parent
f2f49c9d8e
commit
fff9686192
@ -69,7 +69,7 @@ class TrashEntry:
|
|||||||
book_id: int
|
book_id: int
|
||||||
title: str
|
title: str
|
||||||
author: str
|
author: str
|
||||||
book_dir: str
|
cover_path: str
|
||||||
mtime: float
|
mtime: float
|
||||||
formats: Sequence[str] = ()
|
formats: Sequence[str] = ()
|
||||||
|
|
||||||
@ -1968,7 +1968,7 @@ class DB:
|
|||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
opf = OPF(os.path.join(x.path, 'metadata.opf'), basedir=x.path)
|
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')
|
base = os.path.join(self.trash_dir, 'f')
|
||||||
um = {'title': unknown, 'authors': au}
|
um = {'title': unknown, 'authors': au}
|
||||||
for x in os.scandir(base):
|
for x in os.scandir(base):
|
||||||
@ -1988,7 +1988,7 @@ class DB:
|
|||||||
else:
|
else:
|
||||||
formats.add(f.name.upper())
|
formats.add(f.name.upper())
|
||||||
if formats:
|
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
|
return books, files
|
||||||
|
|
||||||
def remove_books(self, path_map, permanent=False):
|
def remove_books(self, path_map, permanent=False):
|
||||||
|
@ -2665,7 +2665,13 @@ class Cache:
|
|||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def list_trash_entries(self):
|
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
|
@write_api
|
||||||
def move_book_from_trash(self, book_id):
|
def move_book_from_trash(self, book_id):
|
||||||
|
@ -281,11 +281,11 @@ class AddRemoveTest(BaseTest):
|
|||||||
self.assertEqual(len(b), 1)
|
self.assertEqual(len(b), 1)
|
||||||
self.assertEqual(len(f), 0)
|
self.assertEqual(len(f), 0)
|
||||||
self.assertEqual(b[0].title, title)
|
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)
|
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)
|
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
|
# test restoring of books
|
||||||
cache = self.init_cache(cl2)
|
cache = self.init_cache(cl2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user