From c8c4df2f317e37144038222d167f7baef4eddf51 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Sat, 12 Aug 2017 15:01:59 +0200 Subject: [PATCH] [fix] util.isEmptyDir() crashes on non-existent dir lfs.dir will crash rather than return nil if directory doesn't exist Proper fix for 9f5e44670183d046054f87b4820bf5d1b35b3b12 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. --- frontend/util.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/util.lua b/frontend/util.lua index eb242d3b8..2147c1f39 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -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