aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2021-03-20 23:44:27 -0300
committerHisham Muhammad <hisham@gobolinux.org>2021-03-22 10:33:10 -0300
commitdcaca50d670b3f5654c109339b6f37c766558eb1 (patch)
tree638faf5df7570aa874bafdb4179d00f18f410bac /src
parentfbd857e1a0b2aae5beb3875427612e41bf67b35e (diff)
downloadluarocks-dcaca50d670b3f5654c109339b6f37c766558eb1.tar.gz
luarocks-dcaca50d670b3f5654c109339b6f37c766558eb1.tar.bz2
luarocks-dcaca50d670b3f5654c109339b6f37c766558eb1.zip
fix: pack: rockspec with a bare file in the url
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/core/dir.lua22
-rw-r--r--src/luarocks/fetch.lua21
2 files changed, 42 insertions, 1 deletions
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
58function dir.normalize(name) 58function dir.normalize(name)
59 local protocol, pathname = dir.split_url(name) 59 local protocol, pathname = dir.split_url(name)
60 pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/") 60 pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/")
61 local pieces = {}
62 local drive = ""
63 if pathname:match("^.:") then
64 drive, pathname = pathname:match("^(.:)(.*)$")
65 end
66 for piece in pathname:gmatch("(.-)/") do
67 if piece == ".." then
68 local prev = pieces[#pieces]
69 if not prev or prev == ".." then
70 table.insert(pieces, "..")
71 elseif prev ~= "" then
72 table.remove(pieces)
73 end
74 elseif piece ~= "." then
75 table.insert(pieces, piece)
76 end
77 end
78 local basename = pathname:match("[^/]+$")
79 if basename then
80 table.insert(pieces, basename)
81 end
82 pathname = drive .. table.concat(pieces, "/")
61 if protocol ~= "file" then pathname = protocol .."://"..pathname end 83 if protocol ~= "file" then pathname = protocol .."://"..pathname end
62 return pathname 84 return pathname
63end 85end
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)
63 63
64 local protocol, pathname = dir.split_url(url) 64 local protocol, pathname = dir.split_url(url)
65 if protocol == "file" then 65 if protocol == "file" then
66 return fs.absolute_name(pathname) 66 local fullname = dir.normalize(fs.absolute_name(pathname))
67 if not fs.exists(fullname) then
68 local hint = (not pathname:match("^/"))
69 and (" - note that given path in rockspec is not absolute: " .. url)
70 or ""
71 return nil, "Local file not found: " .. fullname .. hint
72 end
73 filename = filename or dir.base_name(pathname)
74 local dstname = dir.normalize(fs.absolute_name(dir.path(".", filename)))
75 local ok, err
76 if fullname == dstname then
77 ok = true
78 else
79 ok, err = fs.copy(fullname, dstname)
80 end
81 if ok then
82 return dstname
83 else
84 return nil, "Failed copying local file " .. fullname .. " to " .. dstname .. ": " .. err
85 end
67 elseif dir.is_basic_protocol(protocol) then 86 elseif dir.is_basic_protocol(protocol) then
68 local ok, name, from_cache = fs.download(url, filename, cache) 87 local ok, name, from_cache = fs.download(url, filename, cache)
69 if not ok then 88 if not ok then