gluon-core: unify indentation in gluon/util.lua
This commit is contained in:
parent
f321af9889
commit
ca1b03b29e
@ -1,25 +1,25 @@
|
||||
-- Writes all lines from the file input to the file output except those starting with prefix
|
||||
-- Doesn't close the output file, but returns the file object
|
||||
local function do_filter_prefix(input, output, prefix)
|
||||
local f = io.open(output, 'w+')
|
||||
local l = prefix:len()
|
||||
local f = io.open(output, 'w+')
|
||||
local l = prefix:len()
|
||||
|
||||
for line in io.lines(input) do
|
||||
if line:sub(1, l) ~= prefix then
|
||||
f:write(line, '\n')
|
||||
end
|
||||
end
|
||||
for line in io.lines(input) do
|
||||
if line:sub(1, l) ~= prefix then
|
||||
f:write(line, '\n')
|
||||
end
|
||||
end
|
||||
|
||||
return f
|
||||
return f
|
||||
end
|
||||
|
||||
|
||||
local function escape_args(ret, arg0, ...)
|
||||
if not arg0 then
|
||||
return ret
|
||||
end
|
||||
if not arg0 then
|
||||
return ret
|
||||
end
|
||||
|
||||
return escape_args(ret .. "'" .. string.gsub(arg0, "'", "'\\''") .. "' ", ...)
|
||||
return escape_args(ret .. "'" .. string.gsub(arg0, "'", "'\\''") .. "' ", ...)
|
||||
end
|
||||
|
||||
|
||||
@ -39,32 +39,32 @@ local uci = require('luci.model.uci').cursor()
|
||||
module 'gluon.util'
|
||||
|
||||
function exec(...)
|
||||
return os.execute(escape_args('', 'exec', ...))
|
||||
return os.execute(escape_args('', 'exec', ...))
|
||||
end
|
||||
|
||||
-- Removes all lines starting with a prefix from a file, optionally adding a new one
|
||||
function replace_prefix(file, prefix, add)
|
||||
local tmp = file .. '.tmp'
|
||||
local f = do_filter_prefix(file, tmp, prefix)
|
||||
if add then
|
||||
f:write(add)
|
||||
end
|
||||
f:close()
|
||||
os.rename(tmp, file)
|
||||
local tmp = file .. '.tmp'
|
||||
local f = do_filter_prefix(file, tmp, prefix)
|
||||
if add then
|
||||
f:write(add)
|
||||
end
|
||||
f:close()
|
||||
os.rename(tmp, file)
|
||||
end
|
||||
|
||||
function readline(fd)
|
||||
local line = fd:read('*l')
|
||||
fd:close()
|
||||
return line
|
||||
local line = fd:read('*l')
|
||||
fd:close()
|
||||
return line
|
||||
end
|
||||
|
||||
function lock(file)
|
||||
exec('lock', file)
|
||||
exec('lock', file)
|
||||
end
|
||||
|
||||
function unlock(file)
|
||||
exec('lock', '-u', file)
|
||||
exec('lock', '-u', file)
|
||||
end
|
||||
|
||||
function node_id()
|
||||
|
Loading…
Reference in New Issue
Block a user