summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-12-22 10:53:43 +0000
committerTed Trask <ttrask01@yahoo.com>2009-12-22 10:53:43 +0000
commit20257900e485b1345e2e1cd68187f5aefea45a52 (patch)
treee4c7cd9d7ab5b369322970e98f7b0ab36e35f899 /lib
parent4ebeb9d3bc2f123f93338bcc8b15ef1723d4eb35 (diff)
downloadacf-core-20257900e485b1345e2e1cd68187f5aefea45a52.tar.bz2
acf-core-20257900e485b1345e2e1cd68187f5aefea45a52.tar.xz
Fixed bug with roles, added follow symlink flag for fs.find, allowed symlinks in /usr/share/acf/app.
Controllers with same name but different prefix were not correct in roles.
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.lua24
-rw-r--r--lib/roles.lua12
2 files changed, 25 insertions, 11 deletions
diff --git a/lib/fs.lua b/lib/fs.lua
index 872e62a..1dab796 100644
--- a/lib/fs.lua
+++ b/lib/fs.lua
@@ -170,28 +170,42 @@ function write_line_file ( path, str )
end
-- returns an array of files under "where" that match "what" (a Lua pattern)
-function find_files_as_array ( what, where, t )
+function find_files_as_array ( what, where, follow, t )
where = where or posix.getcwd()
what = what or ".*"
t = t or {}
- if fs.is_dir(where) then
+
+ local link
+ if follow and fs.is_link(where) then
+ link = posix.readlink(where)
+ if not string.find(link, "^/") then
+ link = dirname(where).."/"..link
+ end
+ end
+
+ if fs.is_dir(where) or (link and fs.is_dir(link)) then
for d in posix.files ( where ) do
if (d == ".") or ( d == "..") then
-- do nothing
elseif fs.is_dir ( where .. "/" .. d ) then
- find_files_as_array (what, where .. "/" .. d, t )
+ find_files_as_array (what, where .. "/" .. d, follow, t )
+ elseif follow and fs.is_link ( where .. "/" .. d ) then
+ find_files_as_array (what, where .. "/" .. d, follow, t )
elseif (string.match (d, "^" .. what .. "$" )) then
table.insert (t, ( string.gsub ( where .. "/" .. d, "/+", "/" ) ) )
end
end
+ elseif (string.match (basename(where), "^" .. what .. "$" )) then
+ table.insert (t, where )
end
+
return (t)
end
-- iterator function for finding dir entries matching (what) (a Lua pattern)
-- starting at where, or currentdir if not specified.
-function find ( what, where )
- local t = find_files_as_array ( what, where )
+function find ( what, where, follow )
+ local t = find_files_as_array ( what, where, follow )
local idx = 0
return function ()
idx = idx + 1
diff --git a/lib/roles.lua b/lib/roles.lua
index b554aea..578a754 100644
--- a/lib/roles.lua
+++ b/lib/roles.lua
@@ -11,13 +11,13 @@ guest_role = "GUEST"
-- returns a table of the *.roles files
-- startdir should be the app dir
local get_roles_candidates = function (startdir)
- return fs.find_files_as_array(".*%.roles", startdir) or {}
+ return fs.find_files_as_array(".*%.roles", startdir, true) or {}
end
-- Return a list of *controller.lua files
list_controllers = function(self)
local list = {}
- for file in fs.find(".*controller%.lua", "/usr/share/acf") do
+ for file in fs.find(".*controller%.lua", "/usr/share/acf", true) do
if not string.find(file, "acf_") then
list[#list + 1] = file
end
@@ -27,7 +27,7 @@ list_controllers = function(self)
end
-- Return information about all or specified controller files
-get_controllers = function(self,controller)
+get_controllers = function(self,pre,controller)
--we get all the controllers
local list = roles.list_controllers()
--we need to grab the directory and name of file
@@ -38,10 +38,10 @@ get_controllers = function(self,controller)
filename = string.match(v,"[^/]*.lua")
name = string.match(filename,"[^.]*")
sname = string.match(filename,"[^-]*")
- temp[sname] = {path=path,prefix=prefix,filename=filename,name=name,sname=sname}
+ temp[prefix.."/"..sname] = {path=path,prefix=prefix,filename=filename,name=name,sname=sname}
end
- if controller then
- return temp[controller]
+ if pre and controller then
+ return temp[pre.."/"..controller]
else
return temp
end