aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-10-12 19:37:46 +0300
committerPeter Melnichenko <mpeterval@gmail.com>2016-10-12 19:48:11 +0300
commit8ce99cc3d2d12eb0b0e4808e5dd1fc402b8603d4 (patch)
treed8ba60e8ec896c3506fdb44e9670d820b9cbfc24
parentd0edbc1873ca9165d968752a67fabc4f580856df (diff)
downloadluarocks-8ce99cc3d2d12eb0b0e4808e5dd1fc402b8603d4.tar.gz
luarocks-8ce99cc3d2d12eb0b0e4808e5dd1fc402b8603d4.tar.bz2
luarocks-8ce99cc3d2d12eb0b0e4808e5dd1fc402b8603d4.zip
Fix manif.find_{current,next}_provider returning "untracked" incorrectly
`find_providers` function used by `manif.find_current_provider` and `manif.find_next_provider` needs relative path from a directory an installed file is deployed in (bin dir, lua dir, or lib dir) to the file. It then uses that path as key in manifest, converting it to module name beforehand for lua files and lib files. It happened to leave a leading slash in this relative path for lua and lib files. `path.path_to_module` has a workaround stripping leading dots caused by leading slashes. However, if the file doesn't have `.lua` extension, slashes are not converted to dots and the workaround doesn't trigger. The issue results in files falsely considered "untracked" and backed-up when reinstalling a different version of a rock, see sailorproject/sailor#138. The fix is to use correct relative paths without leading slashes.
-rw-r--r--src/luarocks/manif.lua11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index e30c2a33..48b4f23d 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -464,6 +464,11 @@ function manif.zip_manifests()
464 end 464 end
465end 465end
466 466
467local function relative_path(from_dir, to_file)
468 -- It is assumed that `from_dir` is prefix of `to_file`.
469 return (to_file:sub(#from_dir + 1):gsub("^[\\/]*", ""))
470end
471
467local function find_providers(file, root) 472local function find_providers(file, root)
468 assert(type(file) == "string") 473 assert(type(file) == "string")
469 root = root or cfg.root_dir 474 root = root or cfg.root_dir
@@ -479,13 +484,13 @@ local function find_providers(file, root)
479 484
480 if util.starts_with(file, deploy_lua) then 485 if util.starts_with(file, deploy_lua) then
481 manifest_tbl = manifest.modules 486 manifest_tbl = manifest.modules
482 key = path.path_to_module(file:sub(#deploy_lua+1):gsub("\\", "/")) 487 key = path.path_to_module(relative_path(deploy_lua, file):gsub("\\", "/"))
483 elseif util.starts_with(file, deploy_lib) then 488 elseif util.starts_with(file, deploy_lib) then
484 manifest_tbl = manifest.modules 489 manifest_tbl = manifest.modules
485 key = path.path_to_module(file:sub(#deploy_lib+1):gsub("\\", "/")) 490 key = path.path_to_module(relative_path(deploy_lib, file):gsub("\\", "/"))
486 elseif util.starts_with(file, deploy_bin) then 491 elseif util.starts_with(file, deploy_bin) then
487 manifest_tbl = manifest.commands 492 manifest_tbl = manifest.commands
488 key = file:sub(#deploy_bin+1):gsub("^[\\/]*", "") 493 key = relative_path(deploy_bin, file)
489 else 494 else
490 assert(false, "Assertion failed: '"..file.."' is not a deployed file.") 495 assert(false, "Assertion failed: '"..file.."' is not a deployed file.")
491 end 496 end