summaryrefslogtreecommitdiff
path: root/lib/gitano/util.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitano/util.lua')
-rw-r--r--lib/gitano/util.lua268
1 files changed, 134 insertions, 134 deletions
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua
index f2dd391..4b0c8c6 100644
--- a/lib/gitano/util.lua
+++ b/lib/gitano/util.lua
@@ -30,14 +30,14 @@ local function run_command(cmd, cmdline, parsed_cmdline, user,
if how ~= "exit" or why ~= 0 then
if not cmd.suppress_error_msgs then
- log.critical(i18n.expand("ERROR_RUNNING_COMMAND",
- {cmd=parsed_cmdline[1], reason=how, code=why}))
- log.critical(i18n.expand("UNABLE_TO_CONTINUE"))
+ log.critical(i18n.expand("ERROR_RUNNING_COMMAND",
+ {cmd=parsed_cmdline[1], reason=how, code=why}))
+ log.critical(i18n.expand("UNABLE_TO_CONTINUE"))
end
return why, cmd.suppress_error_msgs
else
log.syslog.info(i18n.expand("MSG_COMPLETED_SUCCESSFULLY",
- {cmd=cmdline}))
+ {cmd=cmdline}))
return 0, false
end
end
@@ -58,10 +58,10 @@ local function _deep_copy(t, memo)
for k, v in pairs(t) do
kk, vv = k, v
if type(k) == "table" then
- kk = _deep_copy(k, memo)
+ kk = _deep_copy(k, memo)
end
if type(v) == "table" then
- vv = _deep_copy(v, memo)
+ vv = _deep_copy(v, memo)
end
ret[kk] = vv
end
@@ -76,43 +76,43 @@ local function _parse_cmdline(cmdline)
local quoting = false
while #cmdline > 0 do
c, cmdline = cmdline:match("^(.)(.*)$")
- if escaping then
- if c == "n" then
- acc = acc .. "\n"
- elseif c == "t" then
- acc = acc .. "\t"
- else
- acc = acc .. c
- end
- escaping = false
+ if escaping then
+ if c == "n" then
+ acc = acc .. "\n"
+ elseif c == "t" then
+ acc = acc .. "\t"
+ else
+ acc = acc .. c
+ end
+ escaping = false
else
- if c == "'" and quoting == false then
- -- Start single quotes
- quoting = c
- elseif c == '"' and quoting == false then
- -- Start double quotes
- quoting = c
- elseif c == "'" and quoting == c then
- -- End single quotes
- quoting = false
- elseif c == '"' and quoting == c then
- -- End double quotes
- quoting = false
- elseif c == "\\" then
- -- A backslash, entering escaping mode
- escaping = true
- elseif quoting then
- -- Within quotes, so accumulate
- acc = acc .. c
- elseif c == " " then
- -- A space and not quoting, so clear the accumulator
- if acc ~= "" then
- r[#r+1] = acc
- end
- acc = ""
- else
- acc = acc .. c
- end
+ if c == "'" and quoting == false then
+ -- Start single quotes
+ quoting = c
+ elseif c == '"' and quoting == false then
+ -- Start double quotes
+ quoting = c
+ elseif c == "'" and quoting == c then
+ -- End single quotes
+ quoting = false
+ elseif c == '"' and quoting == c then
+ -- End double quotes
+ quoting = false
+ elseif c == "\\" then
+ -- A backslash, entering escaping mode
+ escaping = true
+ elseif quoting then
+ -- Within quotes, so accumulate
+ acc = acc .. c
+ elseif c == " " then
+ -- A space and not quoting, so clear the accumulator
+ if acc ~= "" then
+ r[#r+1] = acc
+ end
+ acc = ""
+ else
+ acc = acc .. c
+ end
end
end
if acc ~= "" then
@@ -162,7 +162,7 @@ local function basename(path, ext)
if ext then
local pat = patesc(ext) .. "$"
if ret:find(pat) then
- ret = ret:sub(1, -(#ext+1))
+ ret = ret:sub(1, -(#ext+1))
end
end
return ret
@@ -180,14 +180,14 @@ local function mkdir_p(path, mode)
if path:find("/") then
local ok, msg = mkdir_p(dirname(path))
if not ok then
- return ok, msg
+ return ok, msg
end
end
local r, err = luxio.mkdir(path, mode)
if r < 0 then
if err == luxio.EEXIST then
- return true
+ return true
end
return nil, "mkdir(" .. path .. "): " .. luxio.strerror(err)
end
@@ -204,18 +204,18 @@ local function rm_rf(path)
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
+ 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
@@ -259,14 +259,14 @@ local function copy_file(from, to, buffer_size)
return false, emsg
end
if bytes then
- ok, write_count, emsg = _write_all(tofile, bytes)
- if not ok then
- fromfile:close()
- tofile:close()
- return false, emsg
- end
+ ok, write_count, emsg = _write_all(tofile, bytes)
+ if not ok then
+ fromfile:close()
+ tofile:close()
+ return false, emsg
+ end
else
- write_count = 0
+ write_count = 0
end
until write_count == 0
fromfile:close()
@@ -287,11 +287,11 @@ local function copy_symlink(from, to)
local link_target, ret, err
ret, link_target = luxio.readlink(from)
if ret == -1 then
- return false, luxio.strerror(link_target)
+ return false, luxio.strerror(link_target)
end
ret, err = luxio.symlink(link_target, to)
if ret ~= 0 then
- return false, luxio.strerror(err)
+ return false, luxio.strerror(err)
end
return true
end
@@ -327,24 +327,24 @@ local function copy_dir(from, to, copy_cbs, filter_cb)
-- Stat and translate mode to type if type unknown
local stat, err = sio.lstat(filefrom)
if not stat then
- log.critical(i18n.expand("ERROR_STAT_FILE_FAILED",
- {file=filefrom, reason=err}))
- return false, err
+ log.critical(i18n.expand("ERROR_STAT_FILE_FAILED",
+ {file=filefrom, reason=err}))
+ return false, err
end
fileinfo.d_type = ({
- [luxio.S_IFBLK] = luxio.DT_BLK,
- [luxio.S_IFCHR] = luxio.DT_CHR,
- [luxio.S_IFDIR] = luxio.DT_DIR,
- [luxio.S_IFIFO] = luxio.DT_FIFO,
- [luxio.S_IFLNK] = luxio.DT_LNK,
- [luxio.S_IFREG] = luxio.DT_REG,
- [luxio.S_IFSOCK] = luxio.DT_SOCK,
- })[luxio.bit.band(stat.mode, luxio.S_IFMT)]
+ [luxio.S_IFBLK] = luxio.DT_BLK,
+ [luxio.S_IFCHR] = luxio.DT_CHR,
+ [luxio.S_IFDIR] = luxio.DT_DIR,
+ [luxio.S_IFIFO] = luxio.DT_FIFO,
+ [luxio.S_IFLNK] = luxio.DT_LNK,
+ [luxio.S_IFREG] = luxio.DT_REG,
+ [luxio.S_IFSOCK] = luxio.DT_SOCK,
+ })[luxio.bit.band(stat.mode, luxio.S_IFMT)]
end
local fileto = path_join(to, filename)
local copycb = copy_cbs[fileinfo.d_type]
if not copycb then
- return false, i18n.expand("ERROR_NO_CB")
+ return false, i18n.expand("ERROR_NO_CB")
end
if filter_cb(from, filename, fileinfo) then
log.ddebug(i18n.expand("MSG_SKIPPING_FILE", {file=filename}))
@@ -352,29 +352,29 @@ local function copy_dir(from, to, copy_cbs, filter_cb)
log.ddebug(i18n.expand("MSG_COPYING_FILE", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto)
if not ret then
- log.critical(i18n.expand("ERROR_COPY_FILE_FAILED",
- {from=filefrom, to=fileto, reason=err}))
+ log.critical(i18n.expand("ERROR_COPY_FILE_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return false, err
end
elseif fileinfo.d_type == luxio.DT_LNK then
log.ddebug(i18n.expand("MSG_COPYING_SYMLINK", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto)
if not ret then
- log.critical(i18n.expand("ERROR_COPY_SYMLINK_FAILED",
- {from=filefrom, to=fileto, reason=err}))
+ log.critical(i18n.expand("ERROR_COPY_SYMLINK_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return false, err
end
elseif fileinfo.d_type == luxio.DT_DIR then
log.ddebug(i18n.expand("MSG_COPYING_DIR", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto, copy_cbs, filter_cb)
if not ret then
- log.critical(i18n.expand("ERROR_COPY_DIR_FAILED",
- {from=filefrom, to=fileto, reason=err}))
+ log.critical(i18n.expand("ERROR_COPY_DIR_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return ret, err
end
else
return false, i18n.expand("ERROR_UNSUPPORTED_TYPE",
- {type=tostring(fileinfo.d_type)})
+ {type=tostring(fileinfo.d_type)})
end
end
return true
@@ -388,9 +388,9 @@ copy_dir_copy_callbacks = {
local function html_escape(s)
return (s:gsub("&", "&amp;"):
- gsub("<", "&lt;"):
- gsub(">", "&gt;"):
- gsub('"', "&quot;"))
+ gsub("<", "&lt;"):
+ gsub(">", "&gt;"):
+ gsub('"', "&quot;"))
end
local tagname_pattern = "^[a-z0-9_%-/]*[a-z0-9_%-]*$"
@@ -414,31 +414,31 @@ local function prep_expansion(str)
while #str > 0 do
c, str = str:match("^(.)(.*)$")
if seen == false then
- if c == "$" then
- seen = c
- else
- acc = acc .. c
- end
+ if c == "$" then
+ seen = c
+ else
+ acc = acc .. c
+ end
elseif seen == "$" then
- if c == "{" then
- seen = c
- if acc ~= "" then
- ret[#ret+1] = acc
- acc = ""
- end
- else
- acc = acc .. c
- seen = false
- end
+ if c == "{" then
+ seen = c
+ if acc ~= "" then
+ ret[#ret+1] = acc
+ acc = ""
+ end
+ else
+ acc = acc .. c
+ seen = false
+ end
elseif seen == "{" then
- if c == "}" then
- seen = false
- assert(acc:match(tagname_pattern), i18n.expand("ERROR_EXPECTED_TAG_NAME"))
- ret[#ret+1] = { acc }
- acc = ""
- else
- acc = acc .. c
- end
+ if c == "}" then
+ seen = false
+ assert(acc:match(tagname_pattern), i18n.expand("ERROR_EXPECTED_TAG_NAME"))
+ ret[#ret+1] = { acc }
+ acc = ""
+ else
+ acc = acc .. c
+ end
end
end
if seen == "$" then
@@ -467,26 +467,26 @@ local function process_expansion(tags, expn, tagsactive)
for i = 1, #expn do
local elem = expn[i]
if type(elem) == "string" then
- r[#r+1] = elem
+ r[#r+1] = elem
else
- elem = elem[1]
- if tagsactive[elem] then
- return do_deny(tags, i18n.expand("ERROR_LOOP_IN_EXPN"))
- end
- local tag = tags[elem]
- if type(tag) == "function" then
- tags[elem] = tag(tags)
- tag = tags[elem]
- end
- if type(tag) == "string" then
- tagsactive[elem] = true
- tag = process_expansion(tags, tag, tagsactive)
- tagsactive[elem] = nil
- else
- -- Can't implicitly expand lists etc.
- tag = ""
- end
- r[#r+1] = tag
+ elem = elem[1]
+ if tagsactive[elem] then
+ return do_deny(tags, i18n.expand("ERROR_LOOP_IN_EXPN"))
+ end
+ local tag = tags[elem]
+ if type(tag) == "function" then
+ tags[elem] = tag(tags)
+ tag = tags[elem]
+ end
+ if type(tag) == "string" then
+ tagsactive[elem] = true
+ tag = process_expansion(tags, tag, tagsactive)
+ tagsactive[elem] = nil
+ else
+ -- Can't implicitly expand lists etc.
+ tag = ""
+ end
+ r[#r+1] = tag
end
end
return tconcat(r)
@@ -502,7 +502,7 @@ local function set(t)
end
local function add_splitable(context, key, value, splitter,
- prefix_name, suffix_name)
+ prefix_name, suffix_name)
if not value or value == "" then
return
end
@@ -511,7 +511,7 @@ local function add_splitable(context, key, value, splitter,
end
_(key, value)
local prefix, suffix = value:match("^(.*%" .. splitter .. ")" ..
- "([^%" .. splitter .. "]+)$")
+ "([^%" .. splitter .. "]+)$")
if prefix then
_(key .. "/" .. prefix_name, prefix:sub(1, -2))
@@ -532,14 +532,14 @@ local function tempfile(repo)
local repopath = repo:fs_path()
local temppattern = path_join(
repopath, ("gitanotmp.%d.%d.XXXXXX"):format(tempfilecounter,
- luxio.getpid()))
+ luxio.getpid()))
tempfilecounter = tempfilecounter + 1
if luxio.mkstemp then
return luxio.mkstemp(temppattern)
end
-- No mkstemp so let's hope that the %d.%d is enough...
local fd = luxio.open(temppattern, luxio.O_RDWR + luxio.O_CREAT,
- tonumber("700", 8))
+ tonumber("700", 8))
return fd, temppattern
end