diff options
author | Ted Trask <ttrask01@yahoo.com> | 2009-01-24 16:52:21 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2009-01-24 16:52:21 +0000 |
commit | 80f200377d7ed85ae3f6a93348b386bb63b4aeed (patch) | |
tree | e93a6adee26e92e79299309b89d8a2be57b9fcf8 /lib/fs.lua | |
parent | a96cb599a24a578a98af2e70da40037c00a7db6b (diff) | |
download | acf-core-80f200377d7ed85ae3f6a93348b386bb63b4aeed.tar.bz2 acf-core-80f200377d7ed85ae3f6a93348b386bb63b4aeed.tar.xz |
Started process of removing as many io.popen calls as possible. Not complete.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1695 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/fs.lua')
-rw-r--r-- | lib/fs.lua | 54 |
1 files changed, 35 insertions, 19 deletions
@@ -53,6 +53,24 @@ function create_directory ( path ) return is_dir(path) end +-- Deletes a directory along with its contents +function remove_directory ( path ) + if fs.is_dir(path) then + for d in posix.files(path) do + if (d == ".") or (d == "..") then + -- ignore + elseif fs.is_dir(path .. "/" .. d) then + remove_directory(path .. "/" ..d) + else + os.remove(path .. "/" ..d) + end + end + os.remove(path) + return true + end + return false +end + -- Creates a blank file (and the directory if necessary) function create_file ( path ) path = path or "" @@ -116,29 +134,27 @@ function write_line_file ( path, str ) end end --- iterator function for finding dir entries matching filespec (what) --- starting at where, or currentdir if not specified. --- Finds regexes, not fileglobs -function find ( what, where ) - -- returns an array of files under "where" that match what "f" - local function find_files_as_array ( f, where, t ) - where = where or posix.getcwd() - f = f or ".*" - t = t or {} - if fs.is_dir(where) then - for d in posix.files ( where ) do - if fs.is_dir ( where .. "/" .. d ) and (d ~= ".") and ( d ~= "..") then - find_files_as_array (f, where .. "/" .. d, t ) - end - if (string.match (d, "^" .. f .. "$" )) then - table.insert (t, ( string.gsub ( where .. "/" .. d, "/+", "/" ) ) ) - end +-- returns an array of files under "where" that match "what" (a Lua pattern) +function find_files_as_array ( what, where, t ) + where = where or posix.getcwd() + what = what or ".*" + t = t or {} + if fs.is_dir(where) then + for d in posix.files ( where ) do + if fs.is_dir ( where .. "/" .. d ) and (d ~= ".") and ( d ~= "..") then + find_files_as_array (what, where .. "/" .. d, t ) + end + if (string.match (d, "^" .. what .. "$" )) then + table.insert (t, ( string.gsub ( where .. "/" .. d, "/+", "/" ) ) ) end end - return (t) end + return (t) +end - -- This is the iterator +-- 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 ) local idx = 0 return function () |