diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2013-05-24 21:11:06 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-05-24 21:11:06 -0300 |
| commit | a26699651c869ac7a47fb579727cc8ec93bcf97c (patch) | |
| tree | 2336c577b08f8b8cdb9398c2943c3f0035e6cce1 | |
| parent | fb8112dd63514bd25db5c655580bed5e7585d186 (diff) | |
| download | luarocks-a26699651c869ac7a47fb579727cc8ec93bcf97c.tar.gz luarocks-a26699651c869ac7a47fb579727cc8ec93bcf97c.tar.bz2 luarocks-a26699651c869ac7a47fb579727cc8ec93bcf97c.zip | |
Support for updating versions of packages that remain with the same upstream URL, but only update their contents.
(Case in point: modules by lhf)
| -rw-r--r-- | src/luarocks/new_version.lua | 97 |
1 files changed, 58 insertions, 39 deletions
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index b91f8aed..cb170321 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua | |||
| @@ -55,26 +55,64 @@ local function try_replace(tbl, field, old, new) | |||
| 55 | end | 55 | end |
| 56 | 56 | ||
| 57 | local function check_url_and_update_md5(out_rs, out_name) | 57 | local function check_url_and_update_md5(out_rs, out_name) |
| 58 | local old_md5 = out_rs.source.md5 | ||
| 58 | out_rs.source.md5 = nil | 59 | out_rs.source.md5 = nil |
| 59 | local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_name) | 60 | local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_name) |
| 60 | if file then | 61 | if not file then |
| 61 | util.printout("File successfully downloaded. Updating MD5 checksum...") | ||
| 62 | out_rs.source.md5 = fs.get_md5(file) | ||
| 63 | fs.change_dir(temp_dir) | ||
| 64 | fs.unpack_archive(file) | ||
| 65 | local base_dir = out_rs.source.dir or fetch.url_to_base_dir(out_rs.source.url) | ||
| 66 | if not fs.exists(base_dir) then | ||
| 67 | util.printerr("Directory "..base_dir.." not found") | ||
| 68 | local files = fs.list_dir() | ||
| 69 | if files[1] and fs.is_dir(files[1]) then | ||
| 70 | util.printerr("Found "..files[1]) | ||
| 71 | out_rs.source.dir = files[1] | ||
| 72 | end | ||
| 73 | end | ||
| 74 | fs.pop_dir() | ||
| 75 | else | ||
| 76 | util.printerr("Warning: invalid URL - "..temp_dir) | 62 | util.printerr("Warning: invalid URL - "..temp_dir) |
| 63 | return true | ||
| 64 | end | ||
| 65 | util.printout("File successfully downloaded. Updating MD5 checksum...") | ||
| 66 | out_rs.source.md5 = fs.get_md5(file) | ||
| 67 | fs.change_dir(temp_dir) | ||
| 68 | fs.unpack_archive(file) | ||
| 69 | local base_dir = out_rs.source.dir or fetch.url_to_base_dir(out_rs.source.url) | ||
| 70 | if not fs.exists(base_dir) then | ||
| 71 | util.printerr("Directory "..base_dir.." not found") | ||
| 72 | local files = fs.list_dir() | ||
| 73 | if files[1] and fs.is_dir(files[1]) then | ||
| 74 | util.printerr("Found "..files[1]) | ||
| 75 | out_rs.source.dir = files[1] | ||
| 76 | end | ||
| 77 | end | 77 | end |
| 78 | fs.pop_dir() | ||
| 79 | return out_rs.source.md5 ~= old_md5 | ||
| 80 | end | ||
| 81 | |||
| 82 | local function update_source_section(out_rs, out_name, url, old_ver, new_ver) | ||
| 83 | if url then | ||
| 84 | out_rs.source.url = url | ||
| 85 | check_url_and_update_md5(out_rs, out_name) | ||
| 86 | return true | ||
| 87 | end | ||
| 88 | if new_ver == old_ver then | ||
| 89 | return true | ||
| 90 | end | ||
| 91 | if not out_rs.source then | ||
| 92 | return nil, "'source' table is missing. Invalid rockspec?" | ||
| 93 | end | ||
| 94 | if out_rs.source.dir then | ||
| 95 | try_replace(out_rs.source, "dir", old_ver, new_ver) | ||
| 96 | end | ||
| 97 | if out_rs.source.file then | ||
| 98 | try_replace(out_rs.source, "file", old_ver, new_ver) | ||
| 99 | end | ||
| 100 | local ok = try_replace(out_rs.source, "url", old_ver, new_ver) | ||
| 101 | if ok then | ||
| 102 | check_url_and_update_md5(out_rs, out_name) | ||
| 103 | return true | ||
| 104 | end | ||
| 105 | ok = try_replace(out_rs.source, "tag", old_ver, new_ver) | ||
| 106 | if not ok then | ||
| 107 | ok = check_url_and_update_md5(out_rs, out_name) | ||
| 108 | if ok then | ||
| 109 | util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.") | ||
| 110 | end | ||
| 111 | end | ||
| 112 | if not ok then | ||
| 113 | return nil, "Failed to determine the location of the new version." | ||
| 114 | end | ||
| 115 | return true | ||
| 78 | end | 116 | end |
| 79 | 117 | ||
| 80 | function run(...) | 118 | function run(...) |
| @@ -117,29 +155,10 @@ function run(...) | |||
| 117 | local out_rs = persist.load_into_table(filename) | 155 | local out_rs = persist.load_into_table(filename) |
| 118 | local out_name = out_rs.package:lower() | 156 | local out_name = out_rs.package:lower() |
| 119 | out_rs.version = new_rockver.."-"..new_rev | 157 | out_rs.version = new_rockver.."-"..new_rev |
| 120 | if url then | 158 | |
| 121 | out_rs.source.url = url | 159 | local ok, err = update_source_section(out_rs, out_name, url, old_ver, new_ver) |
| 122 | check_url_and_update_md5(out_rs, out_name) | 160 | if not ok then return nil, err end |
| 123 | else | 161 | |
| 124 | if new_ver ~= old_ver then | ||
| 125 | if out_rs.source and out_rs.source.dir then | ||
| 126 | try_replace(out_rs.source, "dir", old_ver, new_ver) | ||
| 127 | end | ||
| 128 | if out_rs.source and out_rs.source.file then | ||
| 129 | try_replace(out_rs.source, "file", old_ver, new_ver) | ||
| 130 | end | ||
| 131 | local ok = try_replace(out_rs.source, "url", old_ver, new_ver) | ||
| 132 | if ok then | ||
| 133 | check_url_and_update_md5(out_rs, out_name) | ||
| 134 | else | ||
| 135 | ok = try_replace(out_rs.source, "tag", old_ver, new_ver) | ||
| 136 | if not ok then | ||
| 137 | return nil, "Failed to determine the location of the new version." | ||
| 138 | end | ||
| 139 | end | ||
| 140 | end | ||
| 141 | end | ||
| 142 | |||
| 143 | if out_rs.build and out_rs.build.type == "module" then | 162 | if out_rs.build and out_rs.build.type == "module" then |
| 144 | out_rs.build.type = "builtin" | 163 | out_rs.build.type = "builtin" |
| 145 | end | 164 | end |
