From: Tobias Ulmer Date: Fri, 6 Dec 2013 14:26:42 +0000 (+0100) Subject: transport: in fetch_file, improve doc and remove strange tmp path splitting X-Git-Tag: e2factory-2.3.15rc1~292 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=121917442c90532bc5ca70a697d8ee0a487c1fb7;p=e2factory.git transport: in fetch_file, improve doc and remove strange tmp path splitting Signed-off-by: Tobias Ulmer --- diff --git a/generic/transport.lua b/generic/transport.lua index c3d024a..c0fbb04 100644 --- a/generic/transport.lua +++ b/generic/transport.lua @@ -159,17 +159,19 @@ local function rsync_ssh_mkdir(opts, user, server, dir) return true, nil end ---- fetch a file from a server +--- Fetch a file from a server. -- @param surl url to the server -- @param location location relative to the server url --- @param destdir where to store the file locally --- @param destname filename of the fetched file --- @return true on success, false on error --- @return an error object on failure +-- @param destdir Where to store the file locally. +-- @param destname Filename of the fetched file (optional). If not specified, +-- the basename of location is used. +-- @return True on success, false on error. +-- @return Error object on failure. function transport.fetch_file(surl, location, destdir, destname) if not destname then destname = e2lib.basename(location) end + local rc, re local e = err.new("transport: fetching file failed") local u, re = url.parse(surl) @@ -201,7 +203,6 @@ function transport.fetch_file(surl, location, destdir, destname) u.transport == "https" then local curl_argv = {} local url_loc = string.format("%s/%s", u.url, location) - local dest_tmp = string.format("%s/%s", destdir, tmpfile) -- use special flags here table.insert(curl_argv, "--create-dirs") table.insert(curl_argv, "--silent") @@ -210,7 +211,7 @@ function transport.fetch_file(surl, location, destdir, destname) table.insert(curl_argv, url_loc) table.insert(curl_argv, "-o") - table.insert(curl_argv, dest_tmp) + table.insert(curl_argv, tmpfile_path) rc, re = e2lib.curl(curl_argv) if not rc then @@ -218,16 +219,17 @@ function transport.fetch_file(surl, location, destdir, destname) end elseif u.transport == "file" then -- rsync "sourcefile" "destdir/destfile" - rc, re = rsync_ssh({}, e2lib.join("/", u.path, location), - destdir .. "/" .. tmpfile) + local argv = {} + table.insert(argv, e2lib.join("/", u.path, location)) + table.insert(argv, tmpfile_path) + rc, re = e2lib.rsync(argv) if not rc then return false, e:cat(re) end elseif u.transport == "rsync+ssh" then - local sdir = "/" .. u.path .. "/" .. location - local ddir = destdir .. "/" .. tmpfile + local sdir = e2lib.join("/", u.path, location) local src = rsync_quote_remote(u.user, u.servername, sdir) - rc, re = rsync_ssh({}, src, ddir) + rc, re = rsync_ssh({}, src, tmpfile_path) if not rc then return false, e:cat(re) end @@ -242,9 +244,8 @@ function transport.fetch_file(surl, location, destdir, destname) local sourcefile = string.format("/%s/%s", u.path, location) sourcefile = e2lib.shquote(sourcefile) sourcefile = sourceserv .. sourcefile - local destfile = string.format("%s/%s", destdir, tmpfile) - rc, re = e2lib.scp({ sourcefile , destfile }) + rc, re = e2lib.scp({ sourcefile , tmpfile_path }) if not rc then return false, e:cat(re) end @@ -260,7 +261,7 @@ function transport.fetch_file(surl, location, destdir, destname) end -- file was moved away above, but remove it from the list anyway e2lib.rmtempfile(tmpfile_path) - return true, nil + return true end --- push a file to a server