Merge pull request #104 from blueyed/util.file_readable-check-for-not-dir
awful.util.file_readable: return false for dirs
This commit is contained in:
commit
5fde04c4cf
|
@ -207,13 +207,18 @@ function util.geticonpath(iconname, exts, dirs, size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if file exists and is readable.
|
--- Check if a file exists, is not readable and not a directory.
|
||||||
-- @param filename The file path
|
-- @param filename The file path.
|
||||||
-- @return True if file exists and readable.
|
-- @return True if file exists and is readable.
|
||||||
function util.file_readable(filename)
|
function util.file_readable(filename)
|
||||||
local file = io.open(filename)
|
local file = io.open(filename)
|
||||||
if file then
|
if file then
|
||||||
|
local _, _, code = file:read(1)
|
||||||
io.close(file)
|
io.close(file)
|
||||||
|
if code == 21 then
|
||||||
|
-- "Is a directory".
|
||||||
|
return false
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue