From 27233997852240cac4aef0cf67f11c09ba619231 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 11 Oct 2015 13:14:15 +0200 Subject: [PATCH] Move is_readable_directory to awful.util.dir_readable --- lib/awful/util.lua | 12 ++++++++++++ lib/menubar/icon_theme.lua | 21 +++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/awful/util.lua b/lib/awful/util.lua index 4fa9b7434..3c77b8e8d 100644 --- a/lib/awful/util.lua +++ b/lib/awful/util.lua @@ -21,6 +21,7 @@ local rtable = table local pairs = pairs local string = string local lgi = require("lgi") +local Gio = require("lgi").Gio local Pango = lgi.Pango local capi = { @@ -202,6 +203,17 @@ function util.file_readable(filename) return false end +--- Check if a path exists, is readable and is a directory. +-- @tparam string path The directory path. +-- @treturn boolean True if dir exists and is readable. +function util.dir_readable(path) + local gfile = Gio.File.new_for_path(path) + local gfileinfo = gfile:query_info("standard::type,access::can-read", + Gio.FileQueryInfoFlags.NONE) + return gfileinfo and gfileinfo:get_file_type() == "DIRECTORY" and + gfileinfo:get_attribute_boolean("access::can-read") +end + local function subset_mask_apply(mask, set) local ret = {} for i = 1, #set do diff --git a/lib/menubar/icon_theme.lua b/lib/menubar/icon_theme.lua index 18e7f38c0..bb7fab633 100644 --- a/lib/menubar/icon_theme.lua +++ b/lib/menubar/icon_theme.lua @@ -14,7 +14,6 @@ local beautiful = require("beautiful") local awful = require("awful") local GLib = require("lgi").GLib -local Gio = require("lgi").Gio local index_theme = require("menubar.index_theme") local ipairs = ipairs @@ -38,32 +37,22 @@ local get_default_base_directories = function() return dirs end -local is_readable_directory = function(path) - local gfile = Gio.File.new_for_path(path) - local gfileinfo = gfile:query_info("standard::type,access::can-read", - Gio.FileQueryInfoFlags.NONE) - if not gfileinfo then return false end -- practically ENOENT - local is_dir = (gfileinfo:get_file_type() == "DIRECTORY") - local is_readable = gfileinfo:get_attribute_boolean("access::can-read") - return is_dir and is_readable -end - local get_pragmatic_base_directories = function() local dirs = {} local dir = GLib.build_filenamev({GLib.get_home_dir(), ".icons"}) - if is_readable_directory(dir) then + if awful.util.dir_readable(dir) then table.insert(dirs, dir) end dir = GLib.build_filenamev({GLib.get_user_data_dir(), "icons"}) - if is_readable_directory(dir) then + if awful.util.dir_readable(dir) then table.insert(dirs, dir) end for _, v in ipairs(GLib.get_system_data_dirs()) do dir = GLib.build_filenamev({v, "icons"}) - if is_readable_directory(dir) then + if awful.util.dir_readable(dir) then table.insert(dirs, dir) end end @@ -71,7 +60,7 @@ local get_pragmatic_base_directories = function() local need_usr_share_pixmaps = true for _, v in ipairs(GLib.get_system_data_dirs()) do dir = GLib.build_filenamev({v, "pixmaps"}) - if is_readable_directory(dir) then + if awful.util.dir_readable(dir) then table.insert(dirs, dir) end if dir == "/usr/share/pixmaps" then @@ -80,7 +69,7 @@ local get_pragmatic_base_directories = function() end dir = "/usr/share/pixmaps" - if need_usr_share_pixmaps and is_readable_directory(dir) then + if need_usr_share_pixmaps and awful.util.dir_readable(dir) then table.insert(dirs, dir) end