diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-10-20 00:41:40 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-10-20 00:41:40 +0300 |
commit | c7b91ce031a3b7877f59951fc8570c97f598e771 (patch) | |
tree | 2f2e15f68cb797776430f493e0341fae8d1daa3f /src | |
parent | ed2cbf4046b76e7f08a17577d286c08f2439e93f (diff) | |
download | luarocks-c7b91ce031a3b7877f59951fc8570c97f598e771.tar.gz luarocks-c7b91ce031a3b7877f59951fc8570c97f598e771.tar.bz2 luarocks-c7b91ce031a3b7877f59951fc8570c97f598e771.zip |
Fix backup of wrapped scripts on deploy
When deploying script to bin/script.bat, check and back up
bin/script.bat, not bin/script.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/repos.lua | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 762192a3..161cdd8a 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
@@ -151,17 +151,6 @@ function repos.run_hook(rockspec, hook_name) | |||
151 | return true | 151 | return true |
152 | end | 152 | end |
153 | 153 | ||
154 | local function install_binary(source, target, name, version) | ||
155 | assert(type(source) == "string") | ||
156 | assert(type(target) == "string") | ||
157 | |||
158 | if fs.is_lua(source) then | ||
159 | return fs.wrap_script(source, target, name, version) | ||
160 | else | ||
161 | return fs.copy_binary(source, target) | ||
162 | end | ||
163 | end | ||
164 | |||
165 | function repos.should_wrap_bin_scripts(rockspec) | 154 | function repos.should_wrap_bin_scripts(rockspec) |
166 | assert(type(rockspec) == "table") | 155 | assert(type(rockspec) == "table") |
167 | 156 | ||
@@ -266,22 +255,24 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
266 | end | 255 | end |
267 | end | 256 | end |
268 | 257 | ||
269 | if fs.exists(target) then | 258 | local ok, err = fs.make_dir(dir.dir_name(target)) |
270 | local backup = target | 259 | if not ok then return nil, err end |
260 | |||
261 | local suffixed_target, mover = move_fn(source, target, name, version) | ||
262 | if fs.exists(suffixed_target) then | ||
263 | local backup = suffixed_target | ||
271 | repeat | 264 | repeat |
272 | backup = backup.."~" | 265 | backup = backup.."~" |
273 | until not fs.exists(backup) -- slight race condition here, but shouldn't be a problem. | 266 | until not fs.exists(backup) -- Slight race condition here, but shouldn't be a problem. |
274 | 267 | ||
275 | util.printerr("Warning: "..target.." is not tracked by this installation of LuaRocks. Moving it to "..backup) | 268 | util.printerr("Warning: "..suffixed_target.." is not tracked by this installation of LuaRocks. Moving it to "..backup) |
276 | local ok, err = fs.move(target, backup) | 269 | local ok, err = fs.move(suffixed_target, backup) |
277 | if not ok then | 270 | if not ok then |
278 | return nil, err | 271 | return nil, err |
279 | end | 272 | end |
280 | end | 273 | end |
281 | 274 | ||
282 | local ok, err = fs.make_dir(dir.dir_name(target)) | 275 | ok, err = mover() |
283 | if not ok then return nil, err end | ||
284 | ok, err = move_fn(source, target, name, version) | ||
285 | fs.remove_dir_tree_if_empty(dir.dir_name(source)) | 276 | fs.remove_dir_tree_if_empty(dir.dir_name(source)) |
286 | return ok, err | 277 | return ok, err |
287 | end | 278 | end |
@@ -289,17 +280,25 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
289 | end | 280 | end |
290 | 281 | ||
291 | local rock_manifest = manif.load_rock_manifest(name, version) | 282 | local rock_manifest = manif.load_rock_manifest(name, version) |
292 | 283 | ||
293 | local ok, err = true | 284 | local function install_binary(source, target, name, version) |
294 | if rock_manifest.bin then | 285 | if wrap_bin_scripts and fs.is_lua(source) then |
295 | local move_bin_fn = wrap_bin_scripts and install_binary or fs.copy_binary | 286 | return target .. (cfg.wrapper_suffix or ""), function() return fs.wrap_script(source, target, name, version) end |
296 | ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir, cfg.deploy_bin_dir, move_bin_fn, cfg.wrapper_suffix) | 287 | else |
288 | return target, function() return fs.copy_binary(source, target) end | ||
289 | end | ||
297 | end | 290 | end |
291 | |||
298 | local function make_mover(perms) | 292 | local function make_mover(perms) |
299 | return function (src, dest) | 293 | return function(source, target) |
300 | return fs.move(src, dest, perms) | 294 | return target, function() return fs.move(source, target, perms) end |
301 | end | 295 | end |
302 | end | 296 | end |
297 | |||
298 | local ok, err = true | ||
299 | if rock_manifest.bin then | ||
300 | ok, err = deploy_file_tree(rock_manifest.bin, path.bin_dir, cfg.deploy_bin_dir, install_binary, cfg.wrapper_suffix) | ||
301 | end | ||
303 | if ok and rock_manifest.lua then | 302 | if ok and rock_manifest.lua then |
304 | ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir, cfg.deploy_lua_dir, make_mover(cfg.perm_read)) | 303 | ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir, cfg.deploy_lua_dir, make_mover(cfg.perm_read)) |
305 | end | 304 | end |