diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-11-12 19:26:38 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-11-29 18:36:42 -0300 |
| commit | d4990de9dcfead8cbef9aec79c0f088655595f11 (patch) | |
| tree | 90c6f3aa23c25598cbde3ed0fc593d85ab5d3eca | |
| parent | f3bb9d5e34a178a2d40e409970c0f60aa13fe657 (diff) | |
| download | luarocks-d4990de9dcfead8cbef9aec79c0f088655595f11.tar.gz luarocks-d4990de9dcfead8cbef9aec79c0f088655595f11.tar.bz2 luarocks-d4990de9dcfead8cbef9aec79c0f088655595f11.zip | |
cache rockspecs and src.rocks and check timestamp
| -rw-r--r-- | src/luarocks/fetch.lua | 50 | ||||
| -rw-r--r-- | src/luarocks/fs/tools.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/manif.lua | 23 |
3 files changed, 52 insertions, 28 deletions
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 6835462a..0fc3f506 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
| @@ -10,6 +10,33 @@ local persist = require("luarocks.persist") | |||
| 10 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
| 11 | local cfg = require("luarocks.core.cfg") | 11 | local cfg = require("luarocks.core.cfg") |
| 12 | 12 | ||
| 13 | function fetch.fetch_caching(url) | ||
| 14 | local repo_url, filename = url:match("^(.*)/([^/]+)$") | ||
| 15 | local name = repo_url:gsub("[/:]","_") | ||
| 16 | local cache_dir = dir.path(cfg.local_cache, name) | ||
| 17 | local ok = fs.make_dir(cache_dir) | ||
| 18 | if not ok then | ||
| 19 | cfg.local_cache = fs.make_temp_dir("local_cache") | ||
| 20 | cache_dir = dir.path(cfg.local_cache, name) | ||
| 21 | ok = fs.make_dir(cache_dir) | ||
| 22 | if not ok then | ||
| 23 | return nil, "Failed creating temporary cache directory "..cache_dir | ||
| 24 | end | ||
| 25 | end | ||
| 26 | |||
| 27 | local cachefile = dir.path(cache_dir, filename) | ||
| 28 | if cfg.aggressive_cache and (not name:match("^manifest")) and fs.exists(cachefile) then | ||
| 29 | print("FAST TRACK!", cfg.aggressive_cache) | ||
| 30 | return cachefile, nil, nil, true | ||
| 31 | end | ||
| 32 | |||
| 33 | local file, err, errcode, from_cache = fetch.fetch_url(url, cachefile, true) | ||
| 34 | if not file then | ||
| 35 | return nil, "Failed downloading "..repo_url..(err and " - "..err or ""), errcode | ||
| 36 | end | ||
| 37 | return file, nil, nil, from_cache | ||
| 38 | end | ||
| 39 | |||
| 13 | --- Fetch a local or remote file. | 40 | --- Fetch a local or remote file. |
| 14 | -- Make a remote or local URL/pathname local, fetching the file if necessary. | 41 | -- Make a remote or local URL/pathname local, fetching the file if necessary. |
| 15 | -- Other "fetch" and "load" functions use this function to obtain files. | 42 | -- Other "fetch" and "load" functions use this function to obtain files. |
| @@ -60,7 +87,7 @@ end | |||
| 60 | -- @return (string, string) or (nil, string, [string]): absolute local pathname of | 87 | -- @return (string, string) or (nil, string, [string]): absolute local pathname of |
| 61 | -- the fetched file and temporary directory name; or nil and an error message | 88 | -- the fetched file and temporary directory name; or nil and an error message |
| 62 | -- followed by an optional error code | 89 | -- followed by an optional error code |
| 63 | function fetch.fetch_url_at_temp_dir(url, tmpname, filename) | 90 | function fetch.fetch_url_at_temp_dir(url, tmpname, filename, cache) |
| 64 | assert(type(url) == "string") | 91 | assert(type(url) == "string") |
| 65 | assert(type(tmpname) == "string") | 92 | assert(type(tmpname) == "string") |
| 66 | assert(type(filename) == "string" or not filename) | 93 | assert(type(filename) == "string" or not filename) |
| @@ -81,11 +108,26 @@ function fetch.fetch_url_at_temp_dir(url, tmpname, filename) | |||
| 81 | util.schedule_function(fs.delete, temp_dir) | 108 | util.schedule_function(fs.delete, temp_dir) |
| 82 | local ok, err = fs.change_dir(temp_dir) | 109 | local ok, err = fs.change_dir(temp_dir) |
| 83 | if not ok then return nil, err end | 110 | if not ok then return nil, err end |
| 84 | local file, err, errcode = fetch.fetch_url(url, filename) | 111 | |
| 112 | local file, err, errcode | ||
| 113 | |||
| 114 | if cache then | ||
| 115 | local cachefile | ||
| 116 | cachefile, err, errcode = fetch.fetch_caching(url) | ||
| 117 | |||
| 118 | if cachefile then | ||
| 119 | file = dir.path(temp_dir, filename) | ||
| 120 | fs.copy(cachefile, file) | ||
| 121 | end | ||
| 122 | else | ||
| 123 | file, err, errcode = fetch.fetch_url(url, filename, cache) | ||
| 124 | end | ||
| 125 | |||
| 85 | fs.pop_dir() | 126 | fs.pop_dir() |
| 86 | if not file then | 127 | if not file then |
| 87 | return nil, "Error fetching file: "..err, errcode | 128 | return nil, "Error fetching file: "..err, errcode |
| 88 | end | 129 | end |
| 130 | |||
| 89 | return file, temp_dir | 131 | return file, temp_dir |
| 90 | end | 132 | end |
| 91 | end | 133 | end |
| @@ -159,7 +201,7 @@ function fetch.fetch_and_unpack_rock(url, dest, verify) | |||
| 159 | local name = dir.base_name(url):match("(.*)%.[^.]*%.rock") | 201 | local name = dir.base_name(url):match("(.*)%.[^.]*%.rock") |
| 160 | local tmpname = "luarocks-rock-" .. name | 202 | local tmpname = "luarocks-rock-" .. name |
| 161 | 203 | ||
| 162 | local rock_file, err, errcode = fetch.fetch_url_at_temp_dir(url, tmpname) | 204 | local rock_file, err, errcode = fetch.fetch_url_at_temp_dir(url, tmpname, nil, true) |
| 163 | if not rock_file then | 205 | if not rock_file then |
| 164 | return nil, "Could not fetch rock file: " .. err, errcode | 206 | return nil, "Could not fetch rock file: " .. err, errcode |
| 165 | end | 207 | end |
| @@ -274,7 +316,7 @@ function fetch.load_rockspec(url, location, verify) | |||
| 274 | filename, err = fetch.fetch_url(url) | 316 | filename, err = fetch.fetch_url(url) |
| 275 | fs.pop_dir() | 317 | fs.pop_dir() |
| 276 | else | 318 | else |
| 277 | filename, err, errcode = fetch.fetch_url_at_temp_dir(url, tmpname) | 319 | filename, err, errcode = fetch.fetch_url_at_temp_dir(url, tmpname, nil, true) |
| 278 | end | 320 | end |
| 279 | if not filename then | 321 | if not filename then |
| 280 | return nil, err, errcode | 322 | return nil, err, errcode |
diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua index ef5abe63..541352c2 100644 --- a/src/luarocks/fs/tools.lua +++ b/src/luarocks/fs/tools.lua | |||
| @@ -15,8 +15,8 @@ do | |||
| 15 | 15 | ||
| 16 | local tool_options = { | 16 | local tool_options = { |
| 17 | downloader = { | 17 | downloader = { |
| 18 | { var = "CURL", name = "curl" }, | ||
| 19 | { var = "WGET", name = "wget" }, | 18 | { var = "WGET", name = "wget" }, |
| 19 | { var = "CURL", name = "curl" }, | ||
| 20 | }, | 20 | }, |
| 21 | md5checker = { | 21 | md5checker = { |
| 22 | { var = "MD5SUM", name = "md5sum" }, | 22 | { var = "MD5SUM", name = "md5sum" }, |
| @@ -168,7 +168,10 @@ function tools.use_downloader(url, filename, cache) | |||
| 168 | if cfg.connection_timeout and cfg.connection_timeout > 0 then | 168 | if cfg.connection_timeout and cfg.connection_timeout > 0 then |
| 169 | curl_cmd = curl_cmd .. "--connect-timeout "..tostring(cfg.connection_timeout).." " | 169 | curl_cmd = curl_cmd .. "--connect-timeout "..tostring(cfg.connection_timeout).." " |
| 170 | end | 170 | end |
| 171 | ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." > "..fs.Q(filename))) | 171 | if cache then |
| 172 | curl_cmd = curl_cmd .. " -R -z \"" .. filename .. "\" " | ||
| 173 | end | ||
| 174 | ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." --output "..fs.Q(filename))) | ||
| 172 | else | 175 | else |
| 173 | return false, "No downloader tool available -- please install 'wget' or 'curl' in your system" | 176 | return false, "No downloader tool available -- please install 'wget' or 'curl' in your system" |
| 174 | end | 177 | end |
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index b32df971..1337cab3 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -65,27 +65,6 @@ function manif.load_rock_manifest(name, version, root) | |||
| 65 | return rock_manifest.rock_manifest | 65 | return rock_manifest.rock_manifest |
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | |||
| 69 | local function fetch_manifest_from(repo_url, filename) | ||
| 70 | local url = dir.path(repo_url, filename) | ||
| 71 | local name = repo_url:gsub("[/:]","_") | ||
| 72 | local cache_dir = dir.path(cfg.local_cache, name) | ||
| 73 | local ok = fs.make_dir(cache_dir) | ||
| 74 | if not ok then | ||
| 75 | cfg.local_cache = fs.make_temp_dir("local_cache") | ||
| 76 | cache_dir = dir.path(cfg.local_cache, name) | ||
| 77 | ok = fs.make_dir(cache_dir) | ||
| 78 | if not ok then | ||
| 79 | return nil, "Failed creating temporary cache directory "..cache_dir | ||
| 80 | end | ||
| 81 | end | ||
| 82 | local file, err, errcode, from_cache = fetch.fetch_url(url, dir.path(cache_dir, filename), true) | ||
| 83 | if not file then | ||
| 84 | return nil, "Failed fetching manifest for "..repo_url..(err and " - "..err or ""), errcode | ||
| 85 | end | ||
| 86 | return file, nil, nil, from_cache | ||
| 87 | end | ||
| 88 | |||
| 89 | --- Load a local or remote manifest describing a repository. | 68 | --- Load a local or remote manifest describing a repository. |
| 90 | -- All functions that use manifest tables assume they were obtained | 69 | -- All functions that use manifest tables assume they were obtained |
| 91 | -- through this function. | 70 | -- through this function. |
| @@ -124,7 +103,7 @@ function manif.load_manifest(repo_url, lua_version, versioned_only) | |||
| 124 | else | 103 | else |
| 125 | local err, errcode | 104 | local err, errcode |
| 126 | for _, filename in ipairs(filenames) do | 105 | for _, filename in ipairs(filenames) do |
| 127 | pathname, err, errcode, from_cache = fetch_manifest_from(repo_url, filename) | 106 | pathname, err, errcode, from_cache = fetch.fetch_caching(dir.path(repo_url, filename)) |
| 128 | if pathname then | 107 | if pathname then |
| 129 | break | 108 | break |
| 130 | end | 109 | end |
