awful.util.file_readable: return false for dirs

This is currently only used for icon lookups / where files are expected.
This commit is contained in:
Daniel Hahler 2015-02-09 20:17:40 +01:00
parent 3a160c9363
commit a0e7f88b00
1 changed files with 8 additions and 3 deletions

View File

@ -207,13 +207,18 @@ function util.geticonpath(iconname, exts, dirs, size)
end
end
--- Check if file exists and is readable.
-- @param filename The file path
-- @return True if file exists and readable.
--- Check if a file exists, is not readable and not a directory.
-- @param filename The file path.
-- @return True if file exists and is readable.
function util.file_readable(filename)
local file = io.open(filename)
if file then
local _, _, code = file:read(1)
io.close(file)
if code == 21 then
-- "Is a directory".
return false
end
return true
end
return false