diff options
author | Ted Trask <ttrask01@yahoo.com> | 2015-05-02 11:06:42 -0400 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2015-05-02 11:07:08 -0400 |
commit | d93ee8df55aa6b41b043614cfae5c3805dac11c9 (patch) | |
tree | d933617760e0bb7f18a165d3f85e810a8d075dd6 | |
parent | 71831dfc470e2aa9c3104294a8c2ca785a480cf8 (diff) | |
download | acf-alpine-baselayout-d93ee8df55aa6b41b043614cfae5c3805dac11c9.tar.bz2 acf-alpine-baselayout-d93ee8df55aa6b41b043614cfae5c3805dac11c9.tar.xz |
Fix exception in logfile-model due to change to luaposix API
Exception caused by calling dir with non-existant path.
While there, changed the readlink API as well.
-rw-r--r-- | logfiles-model.lua | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/logfiles-model.lua b/logfiles-model.lua index 590b3ae..9fa36e7 100644 --- a/logfiles-model.lua +++ b/logfiles-model.lua @@ -1,7 +1,8 @@ -- acf model for displaying logfiles local mymodule = {} -posix = require("posix") +dirent = require("posix.dirent") +unistd = require("posix.unistd") modelfunctions = require("modelfunctions") fs = require("acf.fs") format = require("acf.format") @@ -11,7 +12,12 @@ local function file_info ( path ) -- Check if file is in use local st = fs.stat(path) while st.type == "link" do - st = fs.stat(posix.readlink(st.path)) + local ok,link = pcall(unistd.readlink, st.path) + if ok and link then + st = fs.stat(link) + else + break + end end local size = st.size or "0" local lastmod = st.mtime or "---" @@ -24,14 +30,23 @@ end local function recursedir(path, filearray) filearray = filearray or {} local k,v - for k,v in pairs(posix.dir(path) or {}) do + local ok, files = pcall(dirent.dir, path) + if not ok then + return {} + end + for k,v in pairs(files) do -- Ignore files that begins with a '.' if not string.match(v, "^%.") then local f = path .. "/" .. v -- If subfolder exists, list files in this subfolder local st = fs.stat(f) while st and st.type == "link" do - st = fs.stat(posix.readlink(st.path)) + local ok,link = pcall(unistd.readlink, st.path) + if ok and link then + st = fs.stat(link) + else + break + end end if st and st.type == "directory" then recursedir(f, filearray) @@ -93,7 +108,12 @@ mymodule.get_filedetails = function (path, grep) if success then local st = fs.stat(path) while st.type == "link" do - st = fs.stat(posix.readlink(st.path)) + local ok,link = pcall(unistd.readlink, st.path) + if ok and link then + st = fs.stat(link) + else + break + end end file = st.path end @@ -170,7 +190,12 @@ mymodule.delete = function (self, filetodelete) else local st = fs.stat(filetodelete.value.filename.value) while st.type == "link" do - st = fs.stat(posix.readlink(st.path)) + local ok,link = pcall(unistd.readlink, st.path) + if ok and link then + st = fs.stat(link) + else + break + end end local status, err = os.remove( st.path ) if err then |