mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
Datastorage: do not create unnecessary folders (#10162)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
-- need low-level mechnism to detect android to avoid recursive dependency
|
||||
-- need low-level mechanism to detect android to avoid recursive dependency
|
||||
local isAndroid, android = pcall(require, "android")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
|
||||
@@ -60,13 +60,23 @@ end
|
||||
|
||||
local function initDataDir()
|
||||
local sub_data_dirs = {
|
||||
"cache", "clipboard",
|
||||
"data", "data/dict", "data/tessdata", "docsettings",
|
||||
"history", "ota", "patches", "plugins",
|
||||
"screenshots", "settings", "styletweaks",
|
||||
"cache",
|
||||
"clipboard",
|
||||
"data",
|
||||
"data/dict",
|
||||
"data/tessdata",
|
||||
-- "docsettings", -- created when needed
|
||||
-- "history", -- legacy/obsolete sidecar files
|
||||
"ota",
|
||||
-- "patches", -- must be created manually by the interested user
|
||||
"plugins",
|
||||
"screenshots",
|
||||
"settings",
|
||||
"styletweaks",
|
||||
}
|
||||
local datadir = DataStorage:getDataDir()
|
||||
for _, dir in ipairs(sub_data_dirs) do
|
||||
local sub_data_dir = string.format("%s/%s", DataStorage:getDataDir(), dir)
|
||||
local sub_data_dir = string.format("%s/%s", datadir, dir)
|
||||
if lfs.attributes(sub_data_dir, "mode") ~= "directory" then
|
||||
lfs.mkdir(sub_data_dir)
|
||||
end
|
||||
|
||||
@@ -125,10 +125,12 @@ function ReadHistory:_read(force_read)
|
||||
end
|
||||
end
|
||||
|
||||
--- Reads history from legacy history folder.
|
||||
--- Reads history from legacy history folder and remove it iff empty.
|
||||
-- Legacy history file is deleted when respective book is opened or deleted.
|
||||
function ReadHistory:_readLegacyHistory()
|
||||
local history_updated
|
||||
local history_dir = DataStorage:getHistoryDir()
|
||||
if not lfs.attributes(history_dir) then return end
|
||||
local history_updated
|
||||
for f in lfs.dir(history_dir) do
|
||||
local legacy_history_file = joinPath(history_dir, f)
|
||||
if lfs.attributes(legacy_history_file, "mode") == "file" then
|
||||
@@ -145,6 +147,7 @@ function ReadHistory:_readLegacyHistory()
|
||||
self:_reduce()
|
||||
self:_flush()
|
||||
end
|
||||
os.remove(history_dir)
|
||||
end
|
||||
|
||||
function ReadHistory:_init()
|
||||
|
||||
@@ -42,8 +42,10 @@ require("dbg"):turnOff()
|
||||
local logger = require("logger")
|
||||
logger:setLevel(logger.levels.warn)
|
||||
|
||||
-- global defaults
|
||||
local DataStorage = require("datastorage")
|
||||
require("libs/libkoreader-lfs").mkdir(DataStorage:getHistoryDir()) -- for legacy history tests
|
||||
|
||||
-- global defaults
|
||||
os.remove(DataStorage:getDataDir() .. "/defaults.tests.lua")
|
||||
os.remove(DataStorage:getDataDir() .. "/defaults.tests.lua.old")
|
||||
G_defaults = require("luadefaults"):open(DataStorage:getDataDir() .. "/defaults.tests.lua")
|
||||
|
||||
@@ -89,6 +89,7 @@ describe("FileManager module", function()
|
||||
local tmpsf = io.open(tmp_sidecar_file, "w")
|
||||
tmpsf:write("{}")
|
||||
tmpsf:close()
|
||||
lfs.mkdir(require("datastorage"):getHistoryDir())
|
||||
local tmp_history = docsettings:getHistoryPath(tmp_fn)
|
||||
local tmpfp = io.open(tmp_history, "w")
|
||||
tmpfp:write("{}")
|
||||
|
||||
@@ -92,6 +92,7 @@ describe("ReadHistory module", function()
|
||||
local h = reload()
|
||||
now = now + 61
|
||||
h:addItem(test_file("a"), now)
|
||||
mkdir(DataStorage:getHistoryDir())
|
||||
touch(legacy_history_file("b"))
|
||||
h = reload()
|
||||
assert.is.same(2, #h.hist)
|
||||
@@ -113,6 +114,7 @@ describe("ReadHistory module", function()
|
||||
local h = reload()
|
||||
now = now + 61
|
||||
h:addItem(test_file("f"), now)
|
||||
mkdir(DataStorage:getHistoryDir())
|
||||
touch(legacy_history_file("c"))
|
||||
touch(legacy_history_file("b"))
|
||||
now = now + 61
|
||||
|
||||
Reference in New Issue
Block a user