menubar.utils: Don't switch between path and GFile
Before this commit, the code always used GFile instances, then used get_path() for a recursive call and turned the path into a GFile instance again. This is not only inefficient, but also causes issues with directories with invalid utf8, because the get_path function returns nil in this case. Fix this by keeping things as a GFile all the time. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
50cfa6c111
commit
f958b6a023
|
@ -252,11 +252,10 @@ end
|
||||||
-- @tparam table callback.programs Paths of found .desktop files.
|
-- @tparam table callback.programs Paths of found .desktop files.
|
||||||
function utils.parse_dir(dir_path, callback)
|
function utils.parse_dir(dir_path, callback)
|
||||||
|
|
||||||
local function parser(dir, programs)
|
local function parser(file, programs)
|
||||||
local f = gio.File.new_for_path(dir)
|
|
||||||
-- Except for "NONE" there is also NOFOLLOW_SYMLINKS
|
-- Except for "NONE" there is also NOFOLLOW_SYMLINKS
|
||||||
local query = gio.FILE_ATTRIBUTE_STANDARD_NAME .. "," .. gio.FILE_ATTRIBUTE_STANDARD_TYPE
|
local query = gio.FILE_ATTRIBUTE_STANDARD_NAME .. "," .. gio.FILE_ATTRIBUTE_STANDARD_TYPE
|
||||||
local enum, err = f:async_enumerate_children(query, gio.FileQueryInfoFlags.NONE)
|
local enum, err = file:async_enumerate_children(query, gio.FileQueryInfoFlags.NONE)
|
||||||
if not enum then
|
if not enum then
|
||||||
gdebug.print_error(err)
|
gdebug.print_error(err)
|
||||||
return
|
return
|
||||||
|
@ -270,14 +269,15 @@ function utils.parse_dir(dir_path, callback)
|
||||||
end
|
end
|
||||||
for _, info in ipairs(list) do
|
for _, info in ipairs(list) do
|
||||||
local file_type = info:get_file_type()
|
local file_type = info:get_file_type()
|
||||||
local file_path = enum:get_child(info):get_path()
|
local file_child = enum:get_child(info)
|
||||||
if file_type == 'REGULAR' then
|
if file_type == 'REGULAR' then
|
||||||
local program = utils.parse_desktop_file(file_path)
|
local path = file_child:get_path()
|
||||||
|
local program = utils.parse_desktop_file(path)
|
||||||
if program then
|
if program then
|
||||||
table.insert(programs, program)
|
table.insert(programs, program)
|
||||||
end
|
end
|
||||||
elseif file_type == 'DIRECTORY' then
|
elseif file_type == 'DIRECTORY' then
|
||||||
parser(file_path, programs)
|
parser(file_child, programs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #list == 0 then
|
if #list == 0 then
|
||||||
|
@ -289,7 +289,7 @@ function utils.parse_dir(dir_path, callback)
|
||||||
|
|
||||||
gio.Async.start(protected_call.call)(function()
|
gio.Async.start(protected_call.call)(function()
|
||||||
local result = {}
|
local result = {}
|
||||||
parser(dir_path, result)
|
parser(gio.File.new_for_path(dir_path), result)
|
||||||
callback(result)
|
callback(result)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue