X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fcore%2Fluasrc%2Ffs.lua;h=a81ff675d41c1b3abd22da6ba4108149288173fb;hb=4fec63df9e4a52ae8bb21b4cac87728ce073554f;hp=f98f6e605cb45dc6faaa842f64cba0ee29a39a7f;hpb=30b216f774c2404a965807ddb93a4a4b2aaeac04;p=project%2Fluci.git diff --git a/libs/core/luasrc/fs.lua b/libs/core/luasrc/fs.lua index f98f6e605..a81ff675d 100644 --- a/libs/core/luasrc/fs.lua +++ b/libs/core/luasrc/fs.lua @@ -176,6 +176,15 @@ end -- @return Number containing the os specific errno on error rmdir = fs.rmdir +local stat_tr = { + reg = "regular", + dir = "directory", + lnk = "link", + chr = "character device", + blk = "block device", + fifo = "fifo", + sock = "socket" +} --- Get information about given file or directory. -- @class function -- @name stat @@ -183,7 +192,14 @@ rmdir = fs.rmdir -- @return Table containing file or directory properties or nil on error -- @return String containing the error description on error -- @return Number containing the os specific errno on error -stat = fs.stat +function stat(path, key) + local data, code, msg = fs.stat(path) + if data then + data.mode = data.modestr + data.type = stat_tr[data.type] or "?" + end + return key and data and data[key] or data, code, msg +end --- Set permissions on given file or directory. -- @class function