diff options
author | Mika Havela <mika.havela@gmail.com> | 2009-07-08 12:41:51 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2009-07-08 12:41:51 +0000 |
commit | a3275e686b437a0ace8d29294f5d3051dbf5bf10 (patch) | |
tree | 2051d2034509116c9e6832b0407097e0b55b65b7 | |
parent | 132e36e8014b662d1a7f83a622abf2901eceba58 (diff) | |
download | acf-rrdtool-a3275e686b437a0ace8d29294f5d3051dbf5bf10.tar.bz2 acf-rrdtool-a3275e686b437a0ace8d29294f5d3051dbf5bf10.tar.xz |
Cleaning up code by using fs.find_files_as_array instead of having own code for searching for files.
-rw-r--r-- | rrdtool-model.lua | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/rrdtool-model.lua b/rrdtool-model.lua index 2b9344a..2acc464 100644 --- a/rrdtool-model.lua +++ b/rrdtool-model.lua @@ -20,25 +20,6 @@ local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " -- ################################################################################ -- LOCAL FUNCTIONS --- Function to recursively insert all filenames in a dir into an array -local function recursedir(path, filearray) - filearray = filearray or {} - local k,v - for k,v in pairs(posix.dir(path) or {}) 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 - if (posix.stat(f).type == "directory") then - recursedir(f, filearray) - else - table.insert(filearray, f) - end - end - end - return filearray -end - local function file_info ( path ) local st = fs.stat(path) local size = st.size or "0" @@ -46,15 +27,10 @@ local function file_info ( path ) return lastmod,size end -local function list_files () +local function list_files (path,search) + local files = fs.find_files_as_array(search, path) + local listed_files = {} - local open_files = {} - local files = {} - local k,v - -- Generate a single table with all the files - for k,v in pairs{databases} do - recursedir(v, files) - end -- Loop through each file and present its info for k,v in pairs(files) do @@ -70,9 +46,8 @@ local function list_files () end - local function validfilename(path) - local files = list_files() + local files = list_files(databases) for k,v in pairs(files.value) do if (v["value"]["filename"]["value"] == path) then return true, tostring(v["value"]["filename"]["value"]) @@ -101,7 +76,7 @@ function setconfigfile(filedetails) end function getrrdlist() - return list_files() + return list_files(databases) end function createnewrrd() |