From eeee65fafbfc6544ea211ec05a2f689b004e90a1 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 7 May 2018 10:41:58 -0300 Subject: luarocks-admin: make `add` work with file:// servers --- src/luarocks/admin/cache.lua | 8 ++++++-- src/luarocks/admin/cmd/add.lua | 9 +++------ 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/luarocks/admin/cache.lua b/src/luarocks/admin/cache.lua index 16a4f5c8..5b54203b 100644 --- a/src/luarocks/admin/cache.lua +++ b/src/luarocks/admin/cache.lua @@ -34,7 +34,9 @@ end function cache.split_server_url(server, url, user, password) local protocol, server_path = dir.split_url(url) - if server_path:match("@") then + if protocol == "file" then + server_path = fs.absolute_name(server_path) + elseif server_path:match("@") then local credentials credentials, server_path = server_path:match("([^@]*)@(.*)") if credentials:match(":") then @@ -43,7 +45,7 @@ function cache.split_server_url(server, url, user, password) user = credentials end end - local local_cache = cfg.local_cache .. "/" .. server + local local_cache = cfg.local_cache .. "/" .. server_path:gsub("[\\/]", "_") return local_cache, protocol, server_path, user, password end @@ -52,6 +54,8 @@ local function download_cache(protocol, server_path, user, password) if protocol == "rsync" then local srv, path = server_path:match("([^/]+)(/.+)") return fs.execute(cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..user.."@"..srv..":"..path.."/ ./") + elseif protocol == "file" then + return fs.copy_contents(server_path, ".") else local login_info = "" if user then login_info = " --user="..user end diff --git a/src/luarocks/admin/cmd/add.lua b/src/luarocks/admin/cmd/add.lua index 6a6f7224..b6c817c6 100644 --- a/src/luarocks/admin/cmd/add.lua +++ b/src/luarocks/admin/cmd/add.lua @@ -45,9 +45,6 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) if not local_cache then return nil, protocol end - if protocol == "file" then - return nil, "Server "..server.." is not recognized, check your configuration." - end if not login_url then login_url = protocol.."://"..server_path @@ -102,6 +99,8 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) if protocol == "rsync" then local srv, path = server_path:match("([^/]+)(/.+)") cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" + elseif protocol == "file" then + return fs.copy_contents(local_cache, server_path) elseif upload_server and upload_server.sftp then local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") cmd = cfg.variables.SCP.." "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 @@ -110,9 +109,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) end util.printout(cmd) - fs.execute(cmd) - - return true + return fs.execute(cmd) end function add.command(flags, ...) -- cgit v1.2.3-55-g6feb