From 80c1e5290c3cd754a1f8f6d53d6cf71242bcb4b5 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Wed, 5 Feb 2020 03:14:21 +0100 Subject: [PATCH] File search & BookInfo: Don't traverse hidden folders if we're not showing them (#5816) * File search: Don't traverse hidden folders if we're not showing them Re https://www.mobileread.com/forums/showpost.php?p=3949194&postcount=21 * Ignore macOS resource forks, too. * Apply the same logic to the BookInfo directory walker * And never ever show resource forks in the FM, either. --- frontend/apps/filemanager/filemanagerfilesearcher.lua | 11 +++++++---- frontend/ui/widget/filechooser.lua | 5 +++-- plugins/coverbrowser.koplugin/bookinfomanager.lua | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/frontend/apps/filemanager/filemanagerfilesearcher.lua b/frontend/apps/filemanager/filemanagerfilesearcher.lua index 10e1fbae8..c143c424a 100644 --- a/frontend/apps/filemanager/filemanagerfilesearcher.lua +++ b/frontend/apps/filemanager/filemanagerfilesearcher.lua @@ -7,7 +7,8 @@ local InputDialog = require("ui/widget/inputdialog") local Menu = require("ui/widget/menu") local UIManager = require("ui/uimanager") local lfs = require("libs/libkoreader-lfs") -local util = require("ffi/util") +local BaseUtil = require("ffi/util") +local util = require("util") local _ = require("gettext") local Screen = require("device").screen @@ -38,10 +39,12 @@ function FileSearcher:readDir() for f in lfs.dir(d) do local fullpath = d.."/"..f local attributes = lfs.attributes(fullpath) or {} - if attributes.mode == "directory" and f ~= "." and f~=".." then + -- Don't traverse hidden folders if we're not showing them + if attributes.mode == "directory" and f ~= "." and f ~= ".." and (G_reader_settings:isTrue("show_hidden") or not util.stringStartsWith(f, ".")) then table.insert(new_dirs, fullpath) table.insert(self.files, {name = f, path = fullpath, attr = attributes}) - elseif attributes.mode == "file" and DocumentRegistry:hasProvider(fullpath) then + -- Always ignore macOS resource forks, too. + elseif attributes.mode == "file" and not util.stringStartsWith(f, "._") and DocumentRegistry:hasProvider(fullpath) then table.insert(self.files, {name = f, path = fullpath, attr = attributes}) end end @@ -93,7 +96,7 @@ function FileSearcher:close() else UIManager:show( InfoMessage:new{ - text = util.template(_("Found no files matching '%1'."), + text = BaseUtil.template(_("Found no files matching '%1'."), self.search_value) } ) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index b3343ba9c..b91e87250 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -65,14 +65,15 @@ function FileChooser:init() local filename = path.."/"..f local attributes = lfs.attributes(filename) if attributes ~= nil then - if attributes.mode == "directory" and f ~= "." and f~=".." then + if attributes.mode == "directory" and f ~= "." and f ~= ".." then if self.dir_filter(filename) then table.insert(dirs, {name = f, suffix = getFileNameSuffix(f), fullpath = filename, attr = attributes}) end - elseif attributes.mode == "file" then + -- Always ignore macOS resource forks. + elseif attributes.mode == "file" and not util.stringStartsWith(f, "._") then if self.file_filter == nil or self.file_filter(filename) or self.show_unsupported then local percent_finished = 0 if self.collate == "percent_unopened_first" or self.collate == "percent_unopened_last" then diff --git a/plugins/coverbrowser.koplugin/bookinfomanager.lua b/plugins/coverbrowser.koplugin/bookinfomanager.lua index 84d868a16..9adf10901 100644 --- a/plugins/coverbrowser.koplugin/bookinfomanager.lua +++ b/plugins/coverbrowser.koplugin/bookinfomanager.lua @@ -661,9 +661,11 @@ local function findFilesInDir(path, recursive) for f in lfs.dir(d) do local fullpath = d.."/"..f local attributes = lfs.attributes(fullpath) - if recursive and attributes.mode == "directory" and f ~= "." and f~=".." then + -- Don't traverse hidden folders if we're not showing them + if recursive and attributes.mode == "directory" and f ~= "." and f ~= ".." and (G_reader_settings:isTrue("show_hidden") or not util.stringStartsWith(f, ".")) then table.insert(new_dirs, fullpath) - elseif attributes.mode == "file" and DocumentRegistry:hasProvider(fullpath) then + -- Always ignore macOS resource forks, too. + elseif attributes.mode == "file" and not util.stringStartsWith(f, "._") and DocumentRegistry:hasProvider(fullpath) then table.insert(files, fullpath) end end