From a68cc783c9fdb20782bb02eb59c39996cd14d71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Gamb=C3=B6ck?= Date: Sun, 2 Jul 2017 15:55:19 +0200 Subject: [PATCH] Add function to check file executable bit This is just a plain copy of the file_readable function, with "read" replaced with "execute". --- lib/gears/filesystem.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/gears/filesystem.lua b/lib/gears/filesystem.lua index d5296caa..55d068eb 100644 --- a/lib/gears/filesystem.lua +++ b/lib/gears/filesystem.lua @@ -53,6 +53,17 @@ function filesystem.file_readable(filename) gfileinfo:get_attribute_boolean("access::can-read") end +--- Check if a file exists, is executable and not a directory. +-- @tparam string filename The file path. +-- @treturn boolean True if file exists and is executable. +function filesystem.file_executable(filename) + local gfile = Gio.File.new_for_path(filename) + local gfileinfo = gfile:query_info("standard::type,access::can-execute", + Gio.FileQueryInfoFlags.NONE) + return gfileinfo and gfileinfo:get_file_type() ~= "DIRECTORY" and + gfileinfo:get_attribute_boolean("access::can-execute") +end + --- Check if a path exists, is readable and a directory. -- @tparam string path The directory path. -- @treturn boolean True if path exists and is readable.