aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpeterv <mpeterval@gmail.com>2016-02-11 16:35:25 +0300
committermpeterv <mpeterval@gmail.com>2016-02-11 16:38:14 +0300
commit137a78e3997cfb97131956d76ddb6b50bd3f8d24 (patch)
tree06dc154973802d015e31e17f0f44232ad16f8d4d
parentd2991be0d3c03ecc953e9d80a90698397492e215 (diff)
downloadluarocks-137a78e3997cfb97131956d76ddb6b50bd3f8d24.tar.gz
luarocks-137a78e3997cfb97131956d76ddb6b50bd3f8d24.tar.bz2
luarocks-137a78e3997cfb97131956d76ddb6b50bd3f8d24.zip
Fix update_source_section in new_version
* Don't confuse cases "MD5 changed with same URL" and "couldn't fetch" * Don't check MD5 if it's not present in the old rockspec * Don't drop errors in fs.get_md5 * Don't drop errors in fetch.find_base_dir
-rw-r--r--src/luarocks/new_version.lua59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua
index 73accf1e..fb813183 100644
--- a/src/luarocks/new_version.lua
+++ b/src/luarocks/new_version.lua
@@ -48,31 +48,47 @@ local function try_replace(tbl, field, old, new)
48 return false 48 return false
49end 49end
50 50
51local function check_url_and_update_md5(out_rs, out_name) 51-- Try to download source file using URL from a rockspec.
52 local old_md5 = out_rs.source.md5 52-- If it specified MD5, update it.
53 out_rs.source.md5 = nil 53-- @return (true, false) if MD5 was not specified or it stayed same,
54 local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_name) 54-- (true, true) if MD5 changed, (nil, string) on error.
55local function check_url_and_update_md5(out_rs)
56 local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package)
55 if not file then 57 if not file then
56 util.printerr("Warning: invalid URL - "..temp_dir) 58 util.printerr("Warning: invalid URL - "..temp_dir)
57 return true 59 return true, false
58 end 60 end
59 util.printout("File successfully downloaded. Updating MD5 checksum...") 61
60 out_rs.source.md5 = fs.get_md5(file)
61 local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) 62 local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir)
62 if not inferred_dir then 63 if not inferred_dir then
63 return nil, found_dir 64 return nil, found_dir
64 end 65 end
66
65 if found_dir and found_dir ~= inferred_dir then 67 if found_dir and found_dir ~= inferred_dir then
66 out_rs.source.dir = found_dir 68 out_rs.source.dir = found_dir
67 end 69 end
68 return out_rs.source.md5 ~= old_md5 70
71 if file then
72 if out_rs.source.md5 then
73 util.printout("File successfully downloaded. Updating MD5 checksum...")
74 local new_md5, err = fs.get_md5(file)
75 if not new_md5 then
76 return nil, err
77 end
78 local old_md5 = out_rs.source.md5
79 out_rs.source.md5 = new_md5
80 return true, new_md5 ~= old_md5
81 else
82 util.printout("File successfully downloaded.")
83 return true, false
84 end
85 end
69end 86end
70 87
71local function update_source_section(out_rs, out_name, url, old_ver, new_ver) 88local function update_source_section(out_rs, url, old_ver, new_ver)
72 if url then 89 if url then
73 out_rs.source.url = url 90 out_rs.source.url = url
74 check_url_and_update_md5(out_rs, out_name) 91 return check_url_and_update_md5(out_rs)
75 return true
76 end 92 end
77 if new_ver == old_ver then 93 if new_ver == old_ver then
78 return true 94 return true
@@ -83,20 +99,19 @@ local function update_source_section(out_rs, out_name, url, old_ver, new_ver)
83 if out_rs.source.file then 99 if out_rs.source.file then
84 try_replace(out_rs.source, "file", old_ver, new_ver) 100 try_replace(out_rs.source, "file", old_ver, new_ver)
85 end 101 end
86 local ok = try_replace(out_rs.source, "url", old_ver, new_ver) 102 if try_replace(out_rs.source, "url", old_ver, new_ver) then
87 if ok then 103 return check_url_and_update_md5(out_rs)
88 check_url_and_update_md5(out_rs, out_name) 104 end
105 if try_replace(out_rs.source, "tag", old_ver, new_ver) then
89 return true 106 return true
90 end 107 end
91 ok = try_replace(out_rs.source, "tag", old_ver, new_ver) 108 -- Couldn't replace anything significant, use the old URL.
109 local ok, md5_changed = check_url_and_update_md5(out_rs)
92 if not ok then 110 if not ok then
93 ok = check_url_and_update_md5(out_rs, out_name) 111 return nil, md5_changed
94 if ok then
95 util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.")
96 end
97 end 112 end
98 if not ok then 113 if md5_changed then
99 return nil, "Failed to determine the location of the new version." 114 util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.")
100 end 115 end
101 return true 116 return true
102end 117end
@@ -142,7 +157,7 @@ function new_version.run(...)
142 local out_name = out_rs.package:lower() 157 local out_name = out_rs.package:lower()
143 out_rs.version = new_rockver.."-"..new_rev 158 out_rs.version = new_rockver.."-"..new_rev
144 159
145 local ok, err = update_source_section(out_rs, out_name, url, old_ver, new_ver) 160 local ok, err = update_source_section(out_rs, url, old_ver, new_ver)
146 if not ok then return nil, err end 161 if not ok then return nil, err end
147 162
148 if out_rs.build and out_rs.build.type == "module" then 163 if out_rs.build and out_rs.build.type == "module" then