diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2015-03-01 00:12:05 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-03-01 00:12:05 -0300 |
| commit | 46f2d252c42d5040a472cb96732b16a19d83efd3 (patch) | |
| tree | 5ed43fa8484ca2c91780de128b998ab6f501106a | |
| parent | 7fe62f1967339b99c362424a42cef2aee6fd45ab (diff) | |
| download | luarocks-46f2d252c42d5040a472cb96732b16a19d83efd3.tar.gz luarocks-46f2d252c42d5040a472cb96732b16a19d83efd3.tar.bz2 luarocks-46f2d252c42d5040a472cb96732b16a19d83efd3.zip | |
Code cleanups suggested by luacheck.
| -rw-r--r-- | src/luarocks/add.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/admin_remove.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/build.lua | 19 | ||||
| -rw-r--r-- | src/luarocks/build/builtin.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/tools/patch.lua | 39 | ||||
| -rw-r--r-- | src/luarocks/tools/zip.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/write_rockspec.lua | 2 |
7 files changed, 36 insertions, 36 deletions
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index fc913c95..81adff9b 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua | |||
| @@ -50,7 +50,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) | |||
| 50 | if not ok then return nil, err end | 50 | if not ok then return nil, err end |
| 51 | 51 | ||
| 52 | local files = {} | 52 | local files = {} |
| 53 | for i, rockfile in ipairs(rockfiles) do | 53 | for _, rockfile in ipairs(rockfiles) do |
| 54 | if fs.exists(rockfile) then | 54 | if fs.exists(rockfile) then |
| 55 | util.printout("Copying file "..rockfile.." to "..local_cache.."...") | 55 | util.printout("Copying file "..rockfile.." to "..local_cache.."...") |
| 56 | local absolute = fs.absolute_name(rockfile) | 56 | local absolute = fs.absolute_name(rockfile) |
diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua index 839121d1..5a1cf20b 100644 --- a/src/luarocks/admin_remove.lua +++ b/src/luarocks/admin_remove.lua | |||
| @@ -46,7 +46,7 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve | |||
| 46 | if not ok then return nil, err end | 46 | if not ok then return nil, err end |
| 47 | 47 | ||
| 48 | local nr_files = 0 | 48 | local nr_files = 0 |
| 49 | for i, rockfile in ipairs(rockfiles) do | 49 | for _, rockfile in ipairs(rockfiles) do |
| 50 | local basename = dir.base_name(rockfile) | 50 | local basename = dir.base_name(rockfile) |
| 51 | local file = dir.path(local_cache, basename) | 51 | local file = dir.path(local_cache, basename) |
| 52 | util.printout("Removing file "..file.."...") | 52 | util.printout("Removing file "..file.."...") |
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 01bfa9d9..96191b11 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
| @@ -133,14 +133,14 @@ local function install_default_docs(name, version) | |||
| 133 | local patterns = { "readme", "license", "copying" } | 133 | local patterns = { "readme", "license", "copying" } |
| 134 | local dest = dir.path(path.install_dir(name, version), "doc") | 134 | local dest = dir.path(path.install_dir(name, version), "doc") |
| 135 | local has_dir = false | 135 | local has_dir = false |
| 136 | for name in fs.dir() do | 136 | for file in fs.dir() do |
| 137 | for _, pattern in ipairs(patterns) do | 137 | for _, pattern in ipairs(patterns) do |
| 138 | if name:lower():match("^"..pattern) then | 138 | if file:lower():match("^"..pattern) then |
| 139 | if not has_dir then | 139 | if not has_dir then |
| 140 | fs.make_dir(dest) | 140 | fs.make_dir(dest) |
| 141 | has_dir = true | 141 | has_dir = true |
| 142 | end | 142 | end |
| 143 | fs.copy(name, dest) | 143 | fs.copy(file, dest) |
| 144 | break | 144 | break |
| 145 | end | 145 | end |
| 146 | end | 146 | end |
| @@ -181,7 +181,8 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m | |||
| 181 | end | 181 | end |
| 182 | end | 182 | end |
| 183 | 183 | ||
| 184 | local ok, err, errcode = deps.check_external_deps(rockspec, "build") | 184 | local ok |
| 185 | ok, err, errcode = deps.check_external_deps(rockspec, "build") | ||
| 185 | if err then | 186 | if err then |
| 186 | return nil, err, errcode | 187 | return nil, err, errcode |
| 187 | end | 188 | end |
| @@ -345,15 +346,17 @@ end | |||
| 345 | function build.build_rock(rock_file, need_to_fetch, deps_mode) | 346 | function build.build_rock(rock_file, need_to_fetch, deps_mode) |
| 346 | assert(type(rock_file) == "string") | 347 | assert(type(rock_file) == "string") |
| 347 | assert(type(need_to_fetch) == "boolean") | 348 | assert(type(need_to_fetch) == "boolean") |
| 348 | 349 | ||
| 349 | local unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_file) | 350 | local ok, err, errcode |
| 351 | local unpack_dir | ||
| 352 | unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_file) | ||
| 350 | if not unpack_dir then | 353 | if not unpack_dir then |
| 351 | return nil, err, errcode | 354 | return nil, err, errcode |
| 352 | end | 355 | end |
| 353 | local rockspec_file = path.rockspec_name_from_rock(rock_file) | 356 | local rockspec_file = path.rockspec_name_from_rock(rock_file) |
| 354 | local ok, err = fs.change_dir(unpack_dir) | 357 | ok, err = fs.change_dir(unpack_dir) |
| 355 | if not ok then return nil, err end | 358 | if not ok then return nil, err end |
| 356 | local ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) | 359 | ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) |
| 357 | fs.pop_dir() | 360 | fs.pop_dir() |
| 358 | return ok, err, errcode | 361 | return ok, err, errcode |
| 359 | end | 362 | end |
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 47aa71fc..57af7dbc 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua | |||
| @@ -74,7 +74,7 @@ function builtin.run(rockspec) | |||
| 74 | add_flags(extras, "-I%s", incdirs) | 74 | add_flags(extras, "-I%s", incdirs) |
| 75 | return execute(variables.CC.." "..variables.CFLAGS, "-c", "-o", object, "-I"..variables.LUA_INCDIR, source, unpack(extras)) | 75 | return execute(variables.CC.." "..variables.CFLAGS, "-c", "-o", object, "-I"..variables.LUA_INCDIR, source, unpack(extras)) |
| 76 | end | 76 | end |
| 77 | compile_library = function(library, objects, libraries, libdirs, name) | 77 | compile_library = function(library, objects, libraries, libdirs) |
| 78 | local extras = { unpack(objects) } | 78 | local extras = { unpack(objects) } |
| 79 | add_flags(extras, "-L%s", libdirs) | 79 | add_flags(extras, "-L%s", libdirs) |
| 80 | add_flags(extras, "-l%s", libraries) | 80 | add_flags(extras, "-l%s", libraries) |
| @@ -170,7 +170,7 @@ function builtin.run(rockspec) | |||
| 170 | end | 170 | end |
| 171 | return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) | 171 | return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) |
| 172 | end | 172 | end |
| 173 | compile_wrapper_binary = function(fullname, name) return true, name end | 173 | compile_wrapper_binary = function(_, name) return true, name end |
| 174 | --TODO EXEWRAPPER | 174 | --TODO EXEWRAPPER |
| 175 | end | 175 | end |
| 176 | 176 | ||
diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index 8df3093d..b53bad61 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua | |||
| @@ -22,8 +22,8 @@ local format = string.format | |||
| 22 | 22 | ||
| 23 | -- logging | 23 | -- logging |
| 24 | local debugmode = false | 24 | local debugmode = false |
| 25 | local function debug(s) end | 25 | local function debug(_) end |
| 26 | local function info(s) end | 26 | local function info(_) end |
| 27 | local function warning(s) io.stderr:write(s .. '\n') end | 27 | local function warning(s) io.stderr:write(s .. '\n') end |
| 28 | 28 | ||
| 29 | -- Returns boolean whether string s2 starts with string s. | 29 | -- Returns boolean whether string s2 starts with string s. |
| @@ -57,27 +57,30 @@ end | |||
| 57 | local function isfile() return true end --FIX? | 57 | local function isfile() return true end --FIX? |
| 58 | 58 | ||
| 59 | local function read_file(filename) | 59 | local function read_file(filename) |
| 60 | local fh, err, oserr = io.open(filename, 'rb') | 60 | local fh, data, err, oserr |
| 61 | fh, err, oserr = io.open(filename, 'rb') | ||
| 61 | if not fh then return fh, err, oserr end | 62 | if not fh then return fh, err, oserr end |
| 62 | local data, err, oserr = fh:read'*a' | 63 | data, err, oserr = fh:read'*a' |
| 63 | fh:close() | 64 | fh:close() |
| 64 | if not data then return nil, err, oserr end | 65 | if not data then return nil, err, oserr end |
| 65 | return data | 66 | return data |
| 66 | end | 67 | end |
| 67 | 68 | ||
| 68 | local function write_file(filename, data) | 69 | local function write_file(filename, data) |
| 69 | local fh, err, oserr = io.open(filename 'wb') | 70 | local fh, status, err, oserr |
| 71 | fh, err, oserr = io.open(filename 'wb') | ||
| 70 | if not fh then return fh, err, oserr end | 72 | if not fh then return fh, err, oserr end |
| 71 | local status, err, oserr = fh:write(data) | 73 | status, err, oserr = fh:write(data) |
| 72 | fh:close() | 74 | fh:close() |
| 73 | if not status then return nil, err, oserr end | 75 | if not status then return nil, err, oserr end |
| 74 | return true | 76 | return true |
| 75 | end | 77 | end |
| 76 | 78 | ||
| 77 | local function file_copy(src, dest) | 79 | local function file_copy(src, dest) |
| 78 | local data, err, oserr = read_file(src) | 80 | local data, status, err, oserr |
| 81 | data, err, oserr = read_file(src) | ||
| 79 | if not data then return data, err, oserr end | 82 | if not data then return data, err, oserr end |
| 80 | local status, err, oserr = write_file(dest) | 83 | status, err, oserr = write_file(dest) |
| 81 | if not status then return status, err, oserr end | 84 | if not status then return status, err, oserr end |
| 82 | return true | 85 | return true |
| 83 | end | 86 | end |
| @@ -420,7 +423,7 @@ local function find_hunk(file, h, hno) | |||
| 420 | end | 423 | end |
| 421 | h.startsrc = location | 424 | h.startsrc = location |
| 422 | h.starttgt = h.starttgt + offset | 425 | h.starttgt = h.starttgt + offset |
| 423 | for i=1,fuzz do | 426 | for _=1,fuzz do |
| 424 | table.remove(h.text, 1) | 427 | table.remove(h.text, 1) |
| 425 | table.remove(h.text, #h.text) | 428 | table.remove(h.text, #h.text) |
| 426 | end | 429 | end |
| @@ -532,7 +535,7 @@ local function patch_hunks(srcname, tgtname, hunks) | |||
| 532 | local line2write = hline:sub(2) | 535 | local line2write = hline:sub(2) |
| 533 | -- detect if line ends are consistent in source file | 536 | -- detect if line ends are consistent in source file |
| 534 | local sum = 0 | 537 | local sum = 0 |
| 535 | for k,v in pairs(lineends) do if v > 0 then sum=sum+1 end end | 538 | for _,v in pairs(lineends) do if v > 0 then sum=sum+1 end end |
| 536 | if sum == 1 then | 539 | if sum == 1 then |
| 537 | local newline | 540 | local newline |
| 538 | for k,v in pairs(lineends) do if v ~= 0 then newline = k end end | 541 | for k,v in pairs(lineends) do if v ~= 0 then newline = k end end |
| @@ -553,7 +556,7 @@ end | |||
| 553 | 556 | ||
| 554 | local function strip_dirs(filename, strip) | 557 | local function strip_dirs(filename, strip) |
| 555 | if strip == nil then return filename end | 558 | if strip == nil then return filename end |
| 556 | for i=1,strip do | 559 | for _=1,strip do |
| 557 | filename=filename:gsub("^[^/]*/", "") | 560 | filename=filename:gsub("^[^/]*/", "") |
| 558 | end | 561 | end |
| 559 | return filename | 562 | return filename |
| @@ -593,7 +596,6 @@ function patch.apply_patch(the_patch, strip) | |||
| 593 | local hunkno = 1 | 596 | local hunkno = 1 |
| 594 | local hunk = hunks[hunkno] | 597 | local hunk = hunks[hunkno] |
| 595 | local hunkfind = {} | 598 | local hunkfind = {} |
| 596 | local hunkreplace = {} | ||
| 597 | local validhunks = 0 | 599 | local validhunks = 0 |
| 598 | local canpatch = false | 600 | local canpatch = false |
| 599 | local hunklineno | 601 | local hunklineno |
| @@ -610,15 +612,10 @@ function patch.apply_patch(the_patch, strip) | |||
| 610 | elseif lineno == hunk.startsrc then | 612 | elseif lineno == hunk.startsrc then |
| 611 | hunkfind = {} | 613 | hunkfind = {} |
| 612 | for _,x in ipairs(hunk.text) do | 614 | for _,x in ipairs(hunk.text) do |
| 613 | if x:sub(1,1) == ' ' or x:sub(1,1) == '-' then | 615 | if x:sub(1,1) == ' ' or x:sub(1,1) == '-' then |
| 614 | hunkfind[#hunkfind+1] = endlstrip(x:sub(2)) | 616 | hunkfind[#hunkfind+1] = endlstrip(x:sub(2)) |
| 615 | end end | 617 | end |
| 616 | hunkreplace = {} | 618 | end |
| 617 | for _,x in ipairs(hunk.text) do | ||
| 618 | if x:sub(1,1) == ' ' or x:sub(1,1) == '+' then | ||
| 619 | hunkreplace[#hunkreplace+1] = endlstrip(x:sub(2)) | ||
| 620 | end end | ||
| 621 | --pprint(hunkreplace) | ||
| 622 | hunklineno = 1 | 619 | hunklineno = 1 |
| 623 | 620 | ||
| 624 | -- todo \ No newline at end of file | 621 | -- todo \ No newline at end of file |
diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua index 40cc089a..83a66434 100644 --- a/src/luarocks/tools/zip.lua +++ b/src/luarocks/tools/zip.lua | |||
| @@ -10,7 +10,7 @@ local dir = require("luarocks.dir") | |||
| 10 | 10 | ||
| 11 | local function number_to_bytestring(number, nbytes) | 11 | local function number_to_bytestring(number, nbytes) |
| 12 | local out = {} | 12 | local out = {} |
| 13 | for i = 1, nbytes do | 13 | for _ = 1, nbytes do |
| 14 | local byte = number % 256 | 14 | local byte = number % 256 |
| 15 | table.insert(out, string.char(byte)) | 15 | table.insert(out, string.char(byte)) |
| 16 | number = (number - byte) / 256 | 16 | number = (number - byte) / 256 |
| @@ -237,7 +237,7 @@ function zip.zip(zipfile, ...) | |||
| 237 | end | 237 | end |
| 238 | end | 238 | end |
| 239 | 239 | ||
| 240 | local ok = zw:close() | 240 | ok = zw:close() |
| 241 | if not ok then | 241 | if not ok then |
| 242 | return false, "error closing "..zipfile | 242 | return false, "error closing "..zipfile |
| 243 | end | 243 | end |
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 403cbc83..5b129ab0 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua | |||
| @@ -219,7 +219,7 @@ function write_rockspec.run(...) | |||
| 219 | version = flags["tag"]:gsub("^v", "") | 219 | version = flags["tag"]:gsub("^v", "") |
| 220 | end | 220 | end |
| 221 | end | 221 | end |
| 222 | 222 | ||
| 223 | local protocol, pathname = dir.split_url(url_or_dir) | 223 | local protocol, pathname = dir.split_url(url_or_dir) |
| 224 | if not fetch.is_basic_protocol(protocol) then | 224 | if not fetch.is_basic_protocol(protocol) then |
| 225 | if not name then | 225 | if not name then |
