diff options
author | Hisham <hisham@gobolinux.org> | 2016-10-20 03:04:19 -0400 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-10-20 03:04:19 -0400 |
commit | 2ced4474d635c11e687ad5b4b5357737503c0b38 (patch) | |
tree | 70e32f174247a73d96fb574b0d65e094165954d2 | |
parent | c5f11204bf774c845fd3b6205e736fcbeaf680c9 (diff) | |
parent | 02dc970620ea88d63093a3f848eac69bb9e3e460 (diff) | |
download | luarocks-2ced4474d635c11e687ad5b4b5357737503c0b38.tar.gz luarocks-2ced4474d635c11e687ad5b4b5357737503c0b38.tar.bz2 luarocks-2ced4474d635c11e687ad5b4b5357737503c0b38.zip |
Merge branch 'master' into luarocks-3
-rw-r--r-- | spec/install_spec.lua | 24 | ||||
-rw-r--r-- | src/luarocks/build.lua | 5 | ||||
-rw-r--r-- | src/luarocks/manif.lua | 54 | ||||
-rw-r--r-- | src/luarocks/repos.lua | 205 | ||||
-rw-r--r-- | test/test_environment.lua | 1 |
5 files changed, 189 insertions, 100 deletions
diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 2bbf4221..a00396fa 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua | |||
@@ -21,6 +21,8 @@ local extra_rocks = { | |||
21 | "/wsapi-1.6-1.src.rock", | 21 | "/wsapi-1.6-1.src.rock", |
22 | "/luafilesystem-1.6.3-2.src.rock", | 22 | "/luafilesystem-1.6.3-2.src.rock", |
23 | "/luafilesystem-1.6.3-1.src.rock", | 23 | "/luafilesystem-1.6.3-1.src.rock", |
24 | "/luacheck-0.7.3-1.src.rock", | ||
25 | "/luacheck-0.8.0-1.src.rock", | ||
24 | } | 26 | } |
25 | 27 | ||
26 | describe("LuaRocks install tests #blackbox #b_install", function() | 28 | describe("LuaRocks install tests #blackbox #b_install", function() |
@@ -87,13 +89,35 @@ describe("LuaRocks install tests #blackbox #b_install", function() | |||
87 | it('LuaRocks install - handle versioned modules when installing another version with --keep #268', function() | 89 | it('LuaRocks install - handle versioned modules when installing another version with --keep #268', function() |
88 | assert.is_true(run.luarocks_bool("install luafilesystem")) | 90 | assert.is_true(run.luarocks_bool("install luafilesystem")) |
89 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) | 91 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) |
92 | |||
90 | assert.is_true(run.luarocks_bool("install luafilesystem 1.6.3-1 --keep")) | 93 | assert.is_true(run.luarocks_bool("install luafilesystem 1.6.3-1 --keep")) |
91 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) | 94 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) |
92 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_3_1-lfs."..test_env.lib_extension)) | 95 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_3_1-lfs."..test_env.lib_extension)) |
96 | |||
93 | assert.is_true(run.luarocks_bool("install luafilesystem")) | 97 | assert.is_true(run.luarocks_bool("install luafilesystem")) |
94 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) | 98 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) |
95 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_3_1-lfs."..test_env.lib_extension)) | 99 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_3_1-lfs."..test_env.lib_extension)) |
96 | end) | 100 | end) |
101 | |||
102 | it('LuaRocks install - handle versioned modules and commands from different files when upgrading #302', function() | ||
103 | io.open(testing_paths.testing_sys_tree .. "/bin/luacheck"..test_env.wrapper_extension, "w"):close() | ||
104 | assert.is_true(run.luarocks_bool("install luacheck 0.7.3 --deps-mode=none")) | ||
105 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/luacheck.lua")) | ||
106 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/bin/luacheck"..test_env.wrapper_extension)) | ||
107 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/bin/luacheck"..test_env.wrapper_extension .. "~")) | ||
108 | |||
109 | assert.is_true(run.luarocks_bool("install luacheck 0.8.0 --deps-mode=none")) | ||
110 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/luacheck/init.lua")) | ||
111 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/bin/luacheck"..test_env.wrapper_extension)) | ||
112 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/luacheck_0_7_3_1-luacheck.lua")) | ||
113 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/bin/luacheck_0_7_3_1-luacheck"..test_env.wrapper_extension)) | ||
114 | |||
115 | assert.is_true(run.luarocks_bool("install luacheck 0.7.3 --keep --deps-mode=none")) | ||
116 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/luacheck/init.lua")) | ||
117 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/bin/luacheck"..test_env.wrapper_extension)) | ||
118 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/luacheck_0_7_3_1-luacheck.lua")) | ||
119 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/bin/luacheck_0_7_3_1-luacheck"..test_env.wrapper_extension)) | ||
120 | end) | ||
97 | 121 | ||
98 | it("LuaRocks install only-deps of luasocket packed rock", function() | 122 | it("LuaRocks install only-deps of luasocket packed rock", function() |
99 | assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) | 123 | assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) |
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 790efef8..3601dc9b 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -70,10 +70,7 @@ local function install_files(files, location, is_module_path, perms) | |||
70 | if not ok then return nil, err end | 70 | if not ok then return nil, err end |
71 | if filename:match("%.lua$") then | 71 | if filename:match("%.lua$") then |
72 | local basename = modname:match("([^.]+)$") | 72 | local basename = modname:match("([^.]+)$") |
73 | local baseinfo = filename:gsub("%.lua$", "") | 73 | filename = basename..".lua" |
74 | if basename ~= baseinfo then | ||
75 | filename = basename..".lua" | ||
76 | end | ||
77 | end | 74 | end |
78 | else | 75 | else |
79 | dest = dir.path(location, dir.dir_name(modname)) | 76 | dest = dir.path(location, dir.dir_name(modname)) |
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index bd6fd6ee..40657fdf 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
@@ -114,33 +114,34 @@ local function relative_path(from_dir, to_file) | |||
114 | return (to_file:sub(#from_dir + 1):gsub("^[\\/]*", "")) | 114 | return (to_file:sub(#from_dir + 1):gsub("^[\\/]*", "")) |
115 | end | 115 | end |
116 | 116 | ||
117 | local function find_providers(file, root) | 117 | local function file_manifest_coordinates(manifest, file, root) |
118 | assert(type(file) == "string") | ||
119 | root = root or cfg.root_dir | ||
120 | |||
121 | local manifest, err = manif.load_local_manifest(path.rocks_dir(root)) | ||
122 | if not manifest then | ||
123 | return nil, "untracked" | ||
124 | end | ||
125 | local deploy_bin = path.deploy_bin_dir(root) | 118 | local deploy_bin = path.deploy_bin_dir(root) |
126 | local deploy_lua = path.deploy_lua_dir(root) | 119 | local deploy_lua = path.deploy_lua_dir(root) |
127 | local deploy_lib = path.deploy_lib_dir(root) | 120 | local deploy_lib = path.deploy_lib_dir(root) |
128 | local key, manifest_tbl | ||
129 | 121 | ||
130 | if util.starts_with(file, deploy_lua) then | 122 | if util.starts_with(file, deploy_lua) then |
131 | manifest_tbl = manifest.modules | 123 | return "modules", path.path_to_module(relative_path(deploy_lua, file):gsub("\\", "/")), deploy_lua |
132 | key = path.path_to_module(relative_path(deploy_lua, file):gsub("\\", "/")) | ||
133 | elseif util.starts_with(file, deploy_lib) then | 124 | elseif util.starts_with(file, deploy_lib) then |
134 | manifest_tbl = manifest.modules | 125 | return "modules", path.path_to_module(relative_path(deploy_lib, file):gsub("\\", "/")), deploy_lib |
135 | key = path.path_to_module(relative_path(deploy_lib, file):gsub("\\", "/")) | ||
136 | elseif util.starts_with(file, deploy_bin) then | 126 | elseif util.starts_with(file, deploy_bin) then |
137 | manifest_tbl = manifest.commands | 127 | return "commands", relative_path(deploy_bin, file), deploy_bin |
138 | key = relative_path(deploy_bin, file) | ||
139 | else | 128 | else |
140 | assert(false, "Assertion failed: '"..file.."' is not a deployed file.") | 129 | assert(false, "Assertion failed: '"..file.."' is not a deployed file.") |
141 | end | 130 | end |
131 | end | ||
132 | |||
133 | local function find_providers(file, root) | ||
134 | assert(type(file) == "string") | ||
135 | root = root or cfg.root_dir | ||
136 | |||
137 | local manifest, err = manif.load_local_manifest(path.rocks_dir(root)) | ||
138 | if not manifest then | ||
139 | return nil, "untracked" | ||
140 | end | ||
141 | |||
142 | local type_key, key = file_manifest_coordinates(manifest, file, root) | ||
142 | 143 | ||
143 | local providers = manifest_tbl[key] | 144 | local providers = manifest[type_key][key] |
144 | if not providers then | 145 | if not providers then |
145 | return nil, "untracked" | 146 | return nil, "untracked" |
146 | end | 147 | end |
@@ -168,4 +169,25 @@ function manif.find_next_provider(file, root) | |||
168 | end | 169 | end |
169 | end | 170 | end |
170 | 171 | ||
172 | --- Given a file conflicting with a module or command | ||
173 | -- provided by a version of a package, return which file | ||
174 | -- in that version corresponds to the conflicting item. | ||
175 | -- @param name string: name of the package with conflicting module or command. | ||
176 | -- @param version string: version of the package with conflicting module or command. | ||
177 | -- @param file string: full, unversioned path to a deployed file. | ||
178 | -- @return string: full, unversioned path to a deployed file in | ||
179 | -- given package that conflicts with given file. | ||
180 | function manif.find_conflicting_file(name, version, file, root) | ||
181 | root = root or cfg.root_dir | ||
182 | |||
183 | local manifest = manif.load_local_manifest(path.rocks_dir(root)) | ||
184 | if not manifest then | ||
185 | return | ||
186 | end | ||
187 | |||
188 | local entry_table = manifest.repository[name][version][1] | ||
189 | local type_key, key, deploy_dir = file_manifest_coordinates(manifest, file, root) | ||
190 | return dir.path(deploy_dir, entry_table[type_key][key]) | ||
191 | end | ||
192 | |||
171 | return manif | 193 | return manif |
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 47a501af..6de844d2 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
@@ -152,50 +152,83 @@ function repos.run_hook(rockspec, hook_name) | |||
152 | return true | 152 | return true |
153 | end | 153 | end |
154 | 154 | ||
155 | local function install_binary(source, target, name, version) | 155 | function repos.should_wrap_bin_scripts(rockspec) |
156 | assert(type(source) == "string") | 156 | assert(type(rockspec) == "table") |
157 | assert(type(target) == "string") | 157 | |
158 | 158 | if cfg.wrap_bin_scripts ~= nil then | |
159 | if fs.is_lua(source) then | 159 | return cfg.wrap_bin_scripts |
160 | return fs.wrap_script(source, target, name, version) | 160 | end |
161 | else | 161 | if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then |
162 | return fs.copy_binary(source, target) | 162 | return false |
163 | end | 163 | end |
164 | return true | ||
164 | end | 165 | end |
165 | 166 | ||
166 | local function resolve_conflict(target, deploy_dir, name, version) | 167 | local function find_suffixed(file, suffix) |
167 | local cname, cversion = manif.find_current_provider(target) | 168 | local filenames = {file} |
168 | if not cname then | 169 | if suffix and suffix ~= "" then |
169 | return nil, cversion | 170 | table.insert(filenames, 1, file .. suffix) |
170 | end | 171 | end |
171 | if name ~= cname or deps.compare_versions(version, cversion) then | 172 | |
172 | local versioned = path.versioned_name(target, deploy_dir, cname, cversion) | 173 | for _, filename in ipairs(filenames) do |
173 | local ok, err = fs.make_dir(dir.dir_name(versioned)) | 174 | if fs.exists(filename) then |
174 | if not ok then return nil, err end | 175 | return filename |
175 | fs.move(target, versioned) | 176 | end |
176 | return target | ||
177 | else | ||
178 | return path.versioned_name(target, deploy_dir, name, version) | ||
179 | end | 177 | end |
180 | end | 178 | end |
181 | 179 | ||
182 | function repos.should_wrap_bin_scripts(rockspec) | 180 | local function move_suffixed(from_file, to_file, suffix) |
183 | assert(type(rockspec) == "table") | 181 | local suffixed_from_file = find_suffixed(from_file, suffix) |
182 | if not suffixed_from_file then | ||
183 | return nil, "File not found" | ||
184 | end | ||
184 | 185 | ||
185 | if cfg.wrap_bin_scripts ~= nil then | 186 | suffix = suffixed_from_file:sub(#from_file + 1) |
186 | return cfg.wrap_bin_scripts | 187 | local suffixed_to_file = to_file .. suffix |
188 | return fs.move(suffixed_from_file, suffixed_to_file) | ||
189 | end | ||
190 | |||
191 | local function delete_suffixed(file, suffix) | ||
192 | local suffixed_file = find_suffixed(file, suffix) | ||
193 | if not suffixed_file then | ||
194 | return nil, "File not found", "not found" | ||
187 | end | 195 | end |
188 | if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then | 196 | |
189 | return false | 197 | fs.delete(suffixed_file) |
198 | if fs.exists(suffixed_file) then | ||
199 | return nil, "Failed deleting " .. suffixed_file, "fail" | ||
190 | end | 200 | end |
201 | |||
191 | return true | 202 | return true |
192 | end | 203 | end |
193 | 204 | ||
205 | local function resolve_conflict(target, deploy_dir, name, version, cur_name, cur_version, suffix) | ||
206 | if name < cur_name or (name == cur_name and deps.compare_versions(version, cur_version)) then | ||
207 | -- New version has priority. Move currently provided version back using versioned name. | ||
208 | local cur_target = manif.find_conflicting_file(cur_name, cur_version, target) | ||
209 | local versioned = path.versioned_name(cur_target, deploy_dir, cur_name, cur_version) | ||
210 | |||
211 | local ok, err = fs.make_dir(dir.dir_name(versioned)) | ||
212 | if not ok then | ||
213 | return nil, err | ||
214 | end | ||
215 | |||
216 | ok, err = move_suffixed(cur_target, versioned, suffix) | ||
217 | if not ok then | ||
218 | return nil, err | ||
219 | end | ||
220 | |||
221 | return target | ||
222 | else | ||
223 | -- Current version has priority, deploy new version using versioned name. | ||
224 | return path.versioned_name(target, deploy_dir, name, version) | ||
225 | end | ||
226 | end | ||
227 | |||
194 | --- Deploy a package from the rocks subdirectory. | 228 | --- Deploy a package from the rocks subdirectory. |
195 | -- It is maintained that for each file the one that is provided | 229 | -- It is maintained that for each module and command the one that is provided |
196 | -- by the newest version of the lexicographically smallest package | 230 | -- by the newest version of the lexicographically smallest package |
197 | -- is installed using unversioned name, and other versions of the file | 231 | -- is installed using unversioned name, and other versions use versioned names. |
198 | -- use versioned names. | ||
199 | -- @param name string: name of package | 232 | -- @param name string: name of package |
200 | -- @param version string: exact package version in string format | 233 | -- @param version string: exact package version in string format |
201 | -- @param wrap_bin_scripts bool: whether commands written in Lua should be wrapped. | 234 | -- @param wrap_bin_scripts bool: whether commands written in Lua should be wrapped. |
@@ -207,51 +240,67 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
207 | assert(type(version) == "string") | 240 | assert(type(version) == "string") |
208 | assert(type(wrap_bin_scripts) == "boolean") | 241 | assert(type(wrap_bin_scripts) == "boolean") |
209 | 242 | ||
210 | local function deploy_file_tree(file_tree, path_fn, deploy_dir, move_fn) | 243 | local function deploy_file_tree(file_tree, path_fn, deploy_dir, move_fn, suffix) |
211 | local source_dir = path_fn(name, version) | 244 | local source_dir = path_fn(name, version) |
212 | return recurse_rock_manifest_tree(file_tree, | 245 | return recurse_rock_manifest_tree(file_tree, |
213 | function(parent_path, parent_module, file) | 246 | function(parent_path, parent_module, file) |
214 | local source = dir.path(source_dir, parent_path, file) | 247 | local source = dir.path(source_dir, parent_path, file) |
215 | local target = dir.path(deploy_dir, parent_path, file) | 248 | local target = dir.path(deploy_dir, parent_path, file) |
216 | local ok, err | 249 | |
217 | if fs.exists(target) then | 250 | local cur_name, cur_version = manif.find_current_provider(target) |
218 | local new_target, err = resolve_conflict(target, deploy_dir, name, version) | 251 | if cur_name then |
219 | if err == "untracked" then | 252 | local resolve_err |
220 | local backup = target | 253 | target, resolve_err = resolve_conflict(target, deploy_dir, name, version, cur_name, cur_version, suffix) |
221 | repeat | 254 | if not target then |
222 | backup = backup.."~" | 255 | return nil, resolve_err |
223 | until not fs.exists(backup) -- slight race condition here, but shouldn't be a problem. | ||
224 | util.printerr("Warning: "..target.." is not tracked by this installation of LuaRocks. Moving it to "..backup) | ||
225 | fs.move(target, backup) | ||
226 | elseif err then | ||
227 | return nil, err.." Cannot install new version." | ||
228 | else | ||
229 | target = new_target | ||
230 | end | 256 | end |
231 | end | 257 | end |
232 | ok, err = fs.make_dir(dir.dir_name(target)) | 258 | |
259 | local ok, err = fs.make_dir(dir.dir_name(target)) | ||
233 | if not ok then return nil, err end | 260 | if not ok then return nil, err end |
234 | ok, err = move_fn(source, target, name, version) | 261 | |
262 | local suffixed_target, mover = move_fn(source, target, name, version) | ||
263 | if fs.exists(suffixed_target) then | ||
264 | local backup = suffixed_target | ||
265 | repeat | ||
266 | backup = backup.."~" | ||
267 | until not fs.exists(backup) -- Slight race condition here, but shouldn't be a problem. | ||
268 | |||
269 | util.printerr("Warning: "..suffixed_target.." is not tracked by this installation of LuaRocks. Moving it to "..backup) | ||
270 | local ok, err = fs.move(suffixed_target, backup) | ||
271 | if not ok then | ||
272 | return nil, err | ||
273 | end | ||
274 | end | ||
275 | |||
276 | ok, err = mover() | ||
235 | fs.remove_dir_tree_if_empty(dir.dir_name(source)) | 277 | fs.remove_dir_tree_if_empty(dir.dir_name(source)) |
236 | if not ok then return nil, err end | 278 | return ok, err |
237 | return true | ||
238 | end | 279 | end |
239 | ) | 280 | ) |
240 | end | 281 | end |
241 | 282 | ||
242 | local rock_manifest, err = manif.load_rock_manifest(name, version) | 283 | local rock_manifest, err = manif.load_rock_manifest(name, version) |
243 | if not rock_manifest then return nil, err end | 284 | if not rock_manifest then return nil, err end |
244 | 285 | ||
245 | local ok, err = true | 286 | local function install_binary(source, target, name, version) |
246 | if rock_manifest.bin then | 287 | if wrap_bin_scripts and fs.is_lua(source) then |
247 | local move_bin_fn = wrap_bin_scripts and install_binary or fs.copy_binary | 288 | return target .. (cfg.wrapper_suffix or ""), function() return fs.wrap_script(source, target, name, version) end |
248 | ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir, cfg.deploy_bin_dir, move_bin_fn) | 289 | else |
290 | return target, function() return fs.copy_binary(source, target) end | ||
291 | end | ||
249 | end | 292 | end |
293 | |||
250 | local function make_mover(perms) | 294 | local function make_mover(perms) |
251 | return function (src, dest) | 295 | return function(source, target) |
252 | return fs.move(src, dest, perms) | 296 | return target, function() return fs.move(source, target, perms) end |
253 | end | 297 | end |
254 | end | 298 | end |
299 | |||
300 | local ok, err = true | ||
301 | if rock_manifest.bin then | ||
302 | ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir, cfg.deploy_bin_dir, install_binary, cfg.wrapper_suffix) | ||
303 | end | ||
255 | if ok and rock_manifest.lua then | 304 | if ok and rock_manifest.lua then |
256 | ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir, cfg.deploy_lua_dir, make_mover(cfg.perm_read)) | 305 | ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir, cfg.deploy_lua_dir, make_mover(cfg.perm_read)) |
257 | end | 306 | end |
@@ -267,26 +316,10 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
267 | return writer.update_manifest(name, version, nil, deps_mode) | 316 | return writer.update_manifest(name, version, nil, deps_mode) |
268 | end | 317 | end |
269 | 318 | ||
270 | local function delete_suffixed(filename, suffix) | ||
271 | local filenames = { filename } | ||
272 | if suffix and suffix ~= "" then filenames = { filename..suffix, filename } end | ||
273 | for _, name in ipairs(filenames) do | ||
274 | if fs.exists(name) then | ||
275 | fs.delete(name) | ||
276 | if fs.exists(name) then | ||
277 | return nil, "Failed deleting "..name, "fail" | ||
278 | end | ||
279 | return true, name | ||
280 | end | ||
281 | end | ||
282 | return false, "File not found", "not found" | ||
283 | end | ||
284 | |||
285 | --- Delete a package from the local repository. | 319 | --- Delete a package from the local repository. |
286 | -- It is maintained that for each file the one that is provided | 320 | -- It is maintained that for each module and command the one that is provided |
287 | -- by the newest version of the lexicographically smallest package | 321 | -- by the newest version of the lexicographically smallest package |
288 | -- is installed using unversioned name, and other versions of the file | 322 | -- is installed using unversioned name, and other versions use versioned names. |
289 | -- use versioned names. | ||
290 | -- @param name string: name of package | 323 | -- @param name string: name of package |
291 | -- @param version string: exact package version in string format | 324 | -- @param version string: exact package version in string format |
292 | -- @param deps_mode: string: Which trees to check dependencies for: | 325 | -- @param deps_mode: string: Which trees to check dependencies for: |
@@ -306,19 +339,31 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
306 | function(parent_path, parent_module, file) | 339 | function(parent_path, parent_module, file) |
307 | local target = dir.path(deploy_dir, parent_path, file) | 340 | local target = dir.path(deploy_dir, parent_path, file) |
308 | local versioned = path.versioned_name(target, deploy_dir, name, version) | 341 | local versioned = path.versioned_name(target, deploy_dir, name, version) |
309 | local ok, name, err = delete_suffixed(versioned, suffix) | 342 | |
343 | local ok, err, err_type = delete_suffixed(versioned, suffix) | ||
310 | if ok then | 344 | if ok then |
311 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) | 345 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) |
312 | return true | 346 | return true |
347 | elseif err_type == "fail" then | ||
348 | return nil, err | ||
349 | end | ||
350 | |||
351 | ok, err = delete_suffixed(target, suffix) | ||
352 | if not ok then | ||
353 | return nil, err | ||
313 | end | 354 | end |
314 | if err == "fail" then return nil, name end | 355 | |
315 | ok, name, err = delete_suffixed(target, suffix) | ||
316 | if err == "fail" then return nil, name end | ||
317 | if not quick then | 356 | if not quick then |
318 | local next_name, next_version = manif.find_next_provider(target) | 357 | local next_name, next_version = manif.find_next_provider(target) |
319 | if next_name then | 358 | if next_name then |
320 | local versioned = path.versioned_name(name, deploy_dir, next_name, next_version) | 359 | local next_target = manif.find_conflicting_file(next_name, next_version, target) |
321 | fs.move(versioned, name) | 360 | local next_versioned = path.versioned_name(next_target, deploy_dir, next_name, next_version) |
361 | |||
362 | ok, err = move_suffixed(next_versioned, next_target, suffix) | ||
363 | if not ok then | ||
364 | return nil, err | ||
365 | end | ||
366 | |||
322 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) | 367 | fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) |
323 | end | 368 | end |
324 | end | 369 | end |
@@ -341,7 +386,7 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
341 | if ok and rock_manifest.lib then | 386 | if ok and rock_manifest.lib then |
342 | ok, err = delete_deployed_file_tree(rock_manifest.lib, cfg.deploy_lib_dir) | 387 | ok, err = delete_deployed_file_tree(rock_manifest.lib, cfg.deploy_lib_dir) |
343 | end | 388 | end |
344 | if err then return nil, err end | 389 | if not ok then return nil, err end |
345 | 390 | ||
346 | fs.delete(path.install_dir(name, version)) | 391 | fs.delete(path.install_dir(name, version)) |
347 | if not get_installed_versions(name) then | 392 | if not get_installed_versions(name) then |
diff --git a/test/test_environment.lua b/test/test_environment.lua index 93f10b83..76dee718 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
@@ -515,6 +515,7 @@ function test_env.setup_specs(extra_rocks) | |||
515 | 515 | ||
516 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) | 516 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) |
517 | test_env.lib_extension = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').lib_extension)\"", false, test_env.env_variables) | 517 | test_env.lib_extension = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').lib_extension)\"", false, test_env.env_variables) |
518 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" | ||
518 | test_env.md5sums = create_md5sums(test_env.testing_paths) | 519 | test_env.md5sums = create_md5sums(test_env.testing_paths) |
519 | test_env.setup_done = true | 520 | test_env.setup_done = true |
520 | title("RUNNING TESTS") | 521 | title("RUNNING TESTS") |