From 50cfa6c1119e49290a8b6e65115bc1a1891f5dc6 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 1 May 2017 13:19:19 +0200 Subject: [PATCH 1/3] Run menubar.utils.parse_dir in protected context Fixes: https://github.com/awesomeWM/awesome/issues/1761 Signed-off-by: Uli Schlachter --- lib/menubar/utils.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/menubar/utils.lua b/lib/menubar/utils.lua index 7c88b3569..a83674485 100644 --- a/lib/menubar/utils.lua +++ b/lib/menubar/utils.lua @@ -287,11 +287,11 @@ function utils.parse_dir(dir_path, callback) enum:async_close() end - gio.Async.start(function() + gio.Async.start(protected_call.call)(function() local result = {} parser(dir_path, result) - protected_call.call(callback, result) - end)() + callback(result) + end) end function utils.compute_textbox_width(textbox, s) From f958b6a023d51d4f5d79cbeb059bf753450a1c11 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 1 May 2017 13:23:05 +0200 Subject: [PATCH 2/3] 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 --- lib/menubar/utils.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/menubar/utils.lua b/lib/menubar/utils.lua index a83674485..1c1cfa7fd 100644 --- a/lib/menubar/utils.lua +++ b/lib/menubar/utils.lua @@ -252,11 +252,10 @@ end -- @tparam table callback.programs Paths of found .desktop files. function utils.parse_dir(dir_path, callback) - local function parser(dir, programs) - local f = gio.File.new_for_path(dir) + local function parser(file, programs) -- Except for "NONE" there is also NOFOLLOW_SYMLINKS 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 gdebug.print_error(err) return @@ -270,14 +269,15 @@ function utils.parse_dir(dir_path, callback) end for _, info in ipairs(list) do 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 - local program = utils.parse_desktop_file(file_path) + local path = file_child:get_path() + local program = utils.parse_desktop_file(path) if program then table.insert(programs, program) end elseif file_type == 'DIRECTORY' then - parser(file_path, programs) + parser(file_child, programs) end end if #list == 0 then @@ -289,7 +289,7 @@ function utils.parse_dir(dir_path, callback) gio.Async.start(protected_call.call)(function() local result = {} - parser(dir_path, result) + parser(gio.File.new_for_path(dir_path), result) callback(result) end) end From 0dbe8a344d9dc51e1887ec2e378e91b74bc309fd Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 1 May 2017 13:26:17 +0200 Subject: [PATCH 3/3] menubar.utils: Fix for invalid utf8 file names The previous commit made this code handle invalid directories correctly. However, it was still possible that we come across invalid file names for which :get_path() returns nil and then we assumed this was a file name. Fix this by silently ignoring such files. Signed-off-by: Uli Schlachter --- lib/menubar/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/menubar/utils.lua b/lib/menubar/utils.lua index 1c1cfa7fd..66dd2a84a 100644 --- a/lib/menubar/utils.lua +++ b/lib/menubar/utils.lua @@ -272,7 +272,7 @@ function utils.parse_dir(dir_path, callback) local file_child = enum:get_child(info) if file_type == 'REGULAR' then local path = file_child:get_path() - local program = utils.parse_desktop_file(path) + local program = path and utils.parse_desktop_file(path) if program then table.insert(programs, program) end