[fix] util.isEmptyDir() crashes on non-existent dir

lfs.dir will crash rather than return nil if directory doesn't exist

Proper fix for 9f5e446701 which is nothing but a workaround. However, I do think creating more of those data dirs automatically is more user-friendly because otherwise Android users will have to look it up or guess.
pull/3094/head
Frans de Jonge 7 years ago
parent 6bdb96c0f8
commit c8c4df2f31

@ -288,7 +288,10 @@ end
---- @treturn bool
function util.isEmptyDir(path)
local lfs = require("libs/libkoreader-lfs")
for filename in lfs.dir(path) do
-- lfs.dir will crash rather than return nil if directory doesn't exist O_o
local ok, iter, dir_obj = pcall(lfs.dir, path)
if not ok then return end
for filename in iter, dir_obj do
if filename ~= '.' and filename ~= '..' then
return false
end

Loading…
Cancel
Save