From 91dc933e27562c980723d0f6fba3406ef703f187 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 21 Feb 2025 12:29:18 -0300 Subject: core.path: more thorough error checking --- src/luarocks/core/path.lua | 11 ++++++++++- src/luarocks/core/path.tl | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua index 2d267e30..2bfe84e0 100644 --- a/src/luarocks/core/path.lua +++ b/src/luarocks/core/path.lua @@ -13,11 +13,20 @@ local dir_sep = package.config:sub(1, 1) function path.rocks_dir(tree) if tree == nil then tree = cfg.root_dir + if tree == nil then + error("root_dir could not be determined in configuration") + end end if type(tree) == "string" then return dir.path(tree, cfg.rocks_subdir) end - return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) + if tree.rocks_dir then + return tree.rocks_dir + end + if tree.root and cfg.rocks_subdir then + return dir.path(tree.root, cfg.rocks_subdir) + end + error("invalid configuration for local repository") end diff --git a/src/luarocks/core/path.tl b/src/luarocks/core/path.tl index 680c3296..cb5d14dc 100644 --- a/src/luarocks/core/path.tl +++ b/src/luarocks/core/path.tl @@ -13,11 +13,20 @@ local dir_sep = package.config:sub(1, 1) function path.rocks_dir(tree: string | Tree): string if tree == nil then tree = cfg.root_dir + if tree == nil then + error("root_dir could not be determined in configuration") + end end if tree is string then return dir.path(tree, cfg.rocks_subdir) end - return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir) + if tree.rocks_dir then + return tree.rocks_dir + end + if tree.root and cfg.rocks_subdir then + return dir.path(tree.root, cfg.rocks_subdir) + end + error("invalid configuration for local repository") end --- Produce a versioned version of a filename. -- cgit v1.2.3-55-g6feb