From dcaca50d670b3f5654c109339b6f37c766558eb1 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 20 Mar 2021 23:44:27 -0300 Subject: fix: pack: rockspec with a bare file in the url --- src/luarocks/core/dir.lua | 22 ++++++++++++++++++++++ src/luarocks/fetch.lua | 21 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/core/dir.lua b/src/luarocks/core/dir.lua index 765a0e58..0da88997 100644 --- a/src/luarocks/core/dir.lua +++ b/src/luarocks/core/dir.lua @@ -58,6 +58,28 @@ end function dir.normalize(name) local protocol, pathname = dir.split_url(name) pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/") + local pieces = {} + local drive = "" + if pathname:match("^.:") then + drive, pathname = pathname:match("^(.:)(.*)$") + end + for piece in pathname:gmatch("(.-)/") do + if piece == ".." then + local prev = pieces[#pieces] + if not prev or prev == ".." then + table.insert(pieces, "..") + elseif prev ~= "" then + table.remove(pieces) + end + elseif piece ~= "." then + table.insert(pieces, piece) + end + end + local basename = pathname:match("[^/]+$") + if basename then + table.insert(pieces, basename) + end + pathname = drive .. table.concat(pieces, "/") if protocol ~= "file" then pathname = protocol .."://"..pathname end return pathname end diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index c8b15d61..1882c348 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -63,7 +63,26 @@ function fetch.fetch_url(url, filename, cache) local protocol, pathname = dir.split_url(url) if protocol == "file" then - return fs.absolute_name(pathname) + local fullname = dir.normalize(fs.absolute_name(pathname)) + if not fs.exists(fullname) then + local hint = (not pathname:match("^/")) + and (" - note that given path in rockspec is not absolute: " .. url) + or "" + return nil, "Local file not found: " .. fullname .. hint + end + filename = filename or dir.base_name(pathname) + local dstname = dir.normalize(fs.absolute_name(dir.path(".", filename))) + local ok, err + if fullname == dstname then + ok = true + else + ok, err = fs.copy(fullname, dstname) + end + if ok then + return dstname + else + return nil, "Failed copying local file " .. fullname .. " to " .. dstname .. ": " .. err + end elseif dir.is_basic_protocol(protocol) then local ok, name, from_cache = fs.download(url, filename, cache) if not ok then -- cgit v1.2.3-55-g6feb