From 4566c9bb20b8986d511c61c1f96bb2333e07bb1d Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 20 Apr 2018 13:13:18 -0300 Subject: path: change signature of root_dir(), make things more consistent --- src/luarocks/core/path.lua | 8 +++++--- src/luarocks/pack.lua | 2 +- src/luarocks/path.lua | 29 +++++++++-------------------- src/luarocks/util.lua | 3 +-- 4 files changed, 16 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua index 125500b7..adebaa23 100644 --- a/src/luarocks/core/path.lua +++ b/src/luarocks/core/path.lua @@ -8,12 +8,14 @@ local require = nil -------------------------------------------------------------------------------- function path.rocks_dir(tree) + if tree == nil then + tree = cfg.root_dir + end if type(tree) == "string" then return dir.path(tree, cfg.rocks_subdir) - else - assert(type(tree) == "table") - return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) end + assert(type(tree) == "table") + return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) end --- Produce a versioned version of a filename. diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 60ba4caf..e0e94283 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -84,7 +84,7 @@ function pack.pack_installed_rock(query, tree) return nil, version end - local root = path.root_dir(repo_url) + local root = path.root_from_rocks_dir(repo_url) local prefix = path.install_dir(name, version, root) if not fs.exists(prefix) then return nil, "'"..name.." "..version.."' does not seem to be an installed rock." diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 4babcb30..a8426090 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -24,27 +24,26 @@ function path.rockspec_name_from_rock(rock_name) return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" end -function path.root_dir(rocks_dir) +function path.root_from_rocks_dir(rocks_dir) assert(type(rocks_dir) == "string") return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") end -function path.deploy_bin_dir(tree) +function path.root_dir(tree) if type(tree) == "string" then - return dir.path(tree, "bin") + return tree else assert(type(tree) == "table") - return tree.bin_dir or dir.path(tree.root, "bin") + return tree.root end end +function path.deploy_bin_dir(tree) + return dir.path(path.root_dir(tree), "bin") +end + function path.manifest_file(tree) - if type(tree) == "string" then - return dir.path(tree, cfg.rocks_subdir, "manifest") - else - assert(type(tree) == "table") - return (tree.rocks_dir and dir.path(tree.rocks_dir, "manifest")) or dir.path(tree.root, cfg.rocks_subdir, "manifest") - end + return dir.path(path.rocks_dir(tree), "manifest") end --- Get the directory for all versions of a package in a tree. @@ -54,7 +53,6 @@ end -- the package (and by extension, the path) exists. function path.versions_dir(name, tree) assert(type(name) == "string" and not name:match("/")) - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name) end @@ -67,7 +65,6 @@ end function path.install_dir(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version) end @@ -80,7 +77,6 @@ end function path.rockspec_file(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec") end @@ -93,7 +89,6 @@ end function path.rock_manifest_file(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version, "rock_manifest") end @@ -106,7 +101,6 @@ end function path.rock_namespace_file(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version, "rock_namespace") end @@ -119,7 +113,6 @@ end function path.lib_dir(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version, "lib") end @@ -132,7 +125,6 @@ end function path.lua_dir(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version, "lua") end @@ -145,7 +137,6 @@ end function path.doc_dir(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version, "doc") end @@ -158,7 +149,6 @@ end function path.conf_dir(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version, "conf") end @@ -172,7 +162,6 @@ end function path.bin_dir(name, version, tree) assert(type(name) == "string" and not name:match("/")) assert(type(version) == "string") - tree = tree or cfg.root_dir return dir.path(path.rocks_dir(tree), name, version, "bin") end diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 9731f034..f96f5c32 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -379,8 +379,7 @@ function util.announce_install(rockspec) suffix = " (license: "..rockspec.description.license..")" end - local root_dir = path.root_dir(cfg.rocks_dir) - util.printout(rockspec.name.." "..rockspec.version.." is now installed in "..root_dir..suffix) + util.printout(rockspec.name.." "..rockspec.version.." is now installed in "..path.root_dir(cfg.root_dir)..suffix) util.printout() end -- cgit v1.2.3-55-g6feb