mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Calibre Metadata: Make sure self.books is always flagged as a JSON array
Ditto for self.driveinfo
This commit is contained in:
@@ -77,10 +77,10 @@ end
|
||||
local CalibreMetadata = {
|
||||
-- info about the library itself. It should
|
||||
-- hold a table with the contents of "driveinfo.calibre"
|
||||
drive = {},
|
||||
drive = rapidjson.array({}),
|
||||
-- info about the books in this library. It should
|
||||
-- hold a table with the contents of "metadata.calibre"
|
||||
books = {},
|
||||
books = rapidjson.array({}),
|
||||
}
|
||||
|
||||
--- loads driveinfo from JSON file
|
||||
@@ -113,12 +113,12 @@ function CalibreMetadata:loadBookList()
|
||||
local attr = lfs.attributes(self.metadata)
|
||||
if not attr then
|
||||
logger.warn("Unable to get file attributes from JSON file:", self.metadata)
|
||||
return {}
|
||||
return rapidjson.array({})
|
||||
end
|
||||
local valid = attr.mode == "file" and attr.size > 0
|
||||
if not valid then
|
||||
logger.warn("File is invalid", self.metadata)
|
||||
return {}
|
||||
return rapidjson.array({})
|
||||
end
|
||||
local books, err
|
||||
local impl = G_reader_settings:readSetting("calibre_json_parser") or attr.size > MAX_JSON_FILESIZE and "safe" or "fast"
|
||||
@@ -132,7 +132,7 @@ function CalibreMetadata:loadBookList()
|
||||
if not books then
|
||||
logger.warn(string.format("Unable to load library from json file %s: \n%s",
|
||||
self.metadata, err))
|
||||
return {}
|
||||
return rapidjson.array({})
|
||||
end
|
||||
return books
|
||||
end
|
||||
@@ -141,7 +141,7 @@ end
|
||||
function CalibreMetadata:saveBookList()
|
||||
local file = self.metadata
|
||||
local books = self.books
|
||||
rapidjson.dump(rapidjson.array(books), file, { pretty = true })
|
||||
rapidjson.dump(books, file, { pretty = true })
|
||||
end
|
||||
|
||||
-- add a book to our books table
|
||||
@@ -221,8 +221,8 @@ end
|
||||
|
||||
-- cleans all temp data stored for current library.
|
||||
function CalibreMetadata:clean()
|
||||
self.books = {}
|
||||
self.drive = {}
|
||||
self.books = rapidjson.array({})
|
||||
self.drive = rapidjson.array({})
|
||||
self.path = nil
|
||||
self.driveinfo = nil
|
||||
self.metadata = nil
|
||||
|
||||
Reference in New Issue
Block a user