From 57e3927cbdc69c58f02b7282ccf0ceeecc7390b1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 18 Oct 2015 13:04:56 +0200 Subject: [PATCH] Add awful.util.is_dir Extracted from https://github.com/awesomeWM/awesome/pull/187. Closes https://github.com/awesomeWM/awesome/pull/536. --- lib/awful/util.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/awful/util.lua b/lib/awful/util.lua index 3c77b8e8d..ca54037d4 100644 --- a/lib/awful/util.lua +++ b/lib/awful/util.lua @@ -214,6 +214,22 @@ function util.dir_readable(path) gfileinfo:get_attribute_boolean("access::can-read") end +--- Check if a path is a directory. +-- @tparam string path +-- @treturn bool True if path exists and is a directory. +function util.is_dir(path) + local file = io.open(path) + if file then + if not file:read(0) -- Not a regular file (might include empty ones). + and file:seek("end") ~= 0 then -- And not a file with size 0. + io.close(file) + return true + end + io.close(file) + end + return false +end + local function subset_mask_apply(mask, set) local ret = {} for i = 1, #set do