From ddbea89de90923bed634166f2939648fcdd36c16 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 12 Apr 2013 15:48:45 -0300 Subject: Make new_version smarter, so it knows how to look inside an updated tarball to check the dir name. This version is able, for example to generate an updated rockspec for lpeg 0.12-rc2 by simply typing `luarocks new_version lpeg 0.12-rc2` --- src/luarocks/fetch.lua | 8 ++++++-- src/luarocks/new_version.lua | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index b835b20e..3bb0cdc0 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -120,6 +120,11 @@ function fetch_and_unpack_rock(rock_file, dest) return unpack_dir end +function url_to_base_dir(url) + local base = dir.base_name(url) + return base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") +end + --- Back-end function that actually loads the local rockspec. -- Performs some validation and postprocessing of the rockspec contents. -- @param filename string: The local filename of the rockspec file. @@ -177,8 +182,7 @@ function load_local_rockspec(filename) rockspec.local_filename = filename local filebase = rockspec.source.file or rockspec.source.url - local base = dir.base_name(filebase) - base = base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") + local base = url_to_base_dir(filebase) rockspec.source.dir = rockspec.source.dir or rockspec.source.module or ((filebase:match(".lua$") or filebase:match(".c$")) and ".") diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index e1e3f80f..66802f0b 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua @@ -60,6 +60,18 @@ local function check_url_and_update_md5(out_rs, out_name) if file then util.printout("File successfully downloaded. Updating MD5 checksum...") out_rs.source.md5 = fs.get_md5(file) + fs.change_dir(temp_dir) + fs.unpack_archive(file) + local base_dir = out_rs.source.dir or fetch.url_to_base_dir(out_rs.source.url) + if not fs.exists(base_dir) then + util.printerr("Directory "..base_dir.." not found") + local files = fs.list_dir() + if files[1] and fs.is_dir(files[1]) then + util.printerr("Found "..files[1]) + out_rs.source.dir = files[1] + end + end + fs.pop_dir() else util.printerr("Warning: invalid URL - "..temp_dir) end @@ -110,6 +122,12 @@ function run(...) check_url_and_update_md5(out_rs, out_name) else if new_ver ~= old_ver then + if out_rs.source and out_rs.source.dir then + try_replace(out_rs.source, "dir", old_ver, new_ver) + end + if out_rs.source and out_rs.source.file then + try_replace(out_rs.source, "file", old_ver, new_ver) + end local ok = try_replace(out_rs.source, "url", old_ver, new_ver) if ok then check_url_and_update_md5(out_rs, out_name) -- cgit v1.2.3-55-g6feb