diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-11-10 16:35:51 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-11-10 16:35:51 +0000 |
commit | 6ce44b14c739e7da79c8504ae799032e67793d55 (patch) | |
tree | 72af615900961f7b2aa5824010fdb2039a6f2de9 | |
parent | f0f1642e67160452ce2a628652b60c78a58ed144 (diff) | |
download | gitano-6ce44b14c739e7da79c8504ae799032e67793d55.tar.gz |
UTIL: Add rm_rf function to gitano.util
-rw-r--r-- | lib/gitano/util.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua index f2db189..c8834d3 100644 --- a/lib/gitano/util.lua +++ b/lib/gitano/util.lua @@ -151,6 +151,37 @@ local function mkdir_p(path, mode) return true end +local function rm_rf(path) + local ret, err, dirp + dirp, err = luxio.opendir(path) + if not dirp then + return false, luxio.strerror(err) + end + local e, i + repeat + e, i = luxio.readdir(dirp) + if e == 0 then + if i.d_name ~= "." and i.d_name ~= ".." then + local elem = path .. "/" .. i.d_name + ret, err = luxio.unlink(elem) + if ret ~= 0 and err == luxio.EISDIR then + ret, err = rm_rf(elem) + if not ret then + return ret, err + end + elseif ret ~= 0 then + return false, luxio.strerror(err) + end + end + end + until not e + + -- explicitly close the dir so we can remove it + luxio.closedir(dirp) + ret, err = luxio.rmdir(path) + return (ret == 0), luxio.strerror(err) +end + local function html_escape(s) return (s:gsub("&", "&"): gsub("<", "<"): @@ -294,6 +325,7 @@ return { basename = basename, mkdir_p = mkdir_p, + rm_rf = rm_rf, html_escape = html_escape, |