From 27ecdd5df9e258a3da879cdcb3432e7ff5123222 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 7 May 2018 11:19:54 -0300 Subject: luarocks-admin: only create index.html if it already exists or --index is given --- src/luarocks/admin/cache.lua | 7 ++++--- src/luarocks/admin/cmd/add.lua | 28 ++++++++++++++++++++-------- src/luarocks/admin/cmd/refresh_cache.lua | 2 +- src/luarocks/admin/cmd/remove.lua | 2 +- src/luarocks/util.lua | 1 + 5 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/luarocks/admin/cache.lua b/src/luarocks/admin/cache.lua index 5b54203b..1fd4d55a 100644 --- a/src/luarocks/admin/cache.lua +++ b/src/luarocks/admin/cache.lua @@ -32,7 +32,7 @@ function cache.get_server_urls(server, upload_server) return download_url, login_url end -function cache.split_server_url(server, url, user, password) +function cache.split_server_url(url, user, password) local protocol, server_path = dir.split_url(url) if protocol == "file" then server_path = fs.absolute_name(server_path) @@ -50,6 +50,7 @@ function cache.split_server_url(server, url, user, password) end local function download_cache(protocol, server_path, user, password) + os.remove("index.html") -- TODO abstract away explicit 'wget' call if protocol == "rsync" then local srv, path = server_path:match("([^/]+)(/.+)") @@ -64,8 +65,8 @@ local function download_cache(protocol, server_path, user, password) end end -function cache.refresh_local_cache(server, url, given_user, given_password) - local local_cache, protocol, server_path, user, password = cache.split_server_url(server, url, given_user, given_password) +function cache.refresh_local_cache(url, given_user, given_password) + local local_cache, protocol, server_path, user, password = cache.split_server_url(url, given_user, given_password) local ok, err = fs.make_dir(local_cache) if not ok then diff --git a/src/luarocks/admin/cmd/add.lua b/src/luarocks/admin/cmd/add.lua index b6c817c6..5cfec980 100644 --- a/src/luarocks/admin/cmd/add.lua +++ b/src/luarocks/admin/cmd/add.lua @@ -18,8 +18,12 @@ Arguments are local files, which may be rockspecs or rocks. The flag --server indicates which server to use. If not given, the default server set in the upload_server variable from the configuration file is used instead. -The flag --no-refresh indicates the local cache should not be refreshed -prior to generation of the updated manifest. + +--no-refresh The local cache should not be refreshed + prior to generation of the updated manifest. +--index Produce an index.html file for the manifest. + This flag is automatically set if an index.html + file already exists. ]] local function zip_manifests() @@ -31,7 +35,7 @@ local function zip_manifests() end end -local function add_files_to_server(refresh, rockfiles, server, upload_server) +local function add_files_to_server(refresh, rockfiles, server, upload_server, do_index) assert(type(refresh) == "boolean" or not refresh) assert(type(rockfiles) == "table") assert(type(server) == "string") @@ -41,7 +45,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) local at = fs.current_dir() local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url - local local_cache, protocol, server_path, user, password = refresh_fn(server, download_url, cfg.upload_user, cfg.upload_password) + local local_cache, protocol, server_path, user, password = refresh_fn(download_url, cfg.upload_user, cfg.upload_password) if not local_cache then return nil, protocol end @@ -76,8 +80,14 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) zip_manifests() - util.printout("Updating index.html...") - index.make_index(local_cache) + if fs.exists("index.html") then + do_index = true + end + + if do_index then + util.printout("Updating index.html...") + index.make_index(local_cache) + end local login_info = "" if user then login_info = " -u "..user end @@ -86,7 +96,9 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) login_url = login_url .. "/" end - table.insert(files, "index.html") + if do_index then + table.insert(files, "index.html") + end table.insert(files, "manifest") for ver in util.lua_versions() do table.insert(files, "manifest-"..ver) @@ -119,7 +131,7 @@ function add.command(flags, ...) end local server, server_table = cache.get_upload_server(flags["server"]) if not server then return nil, server_table end - return add_files_to_server(not flags["no-refresh"], files, server, server_table) + return add_files_to_server(not flags["no-refresh"], files, server, server_table, flags["index"]) end diff --git a/src/luarocks/admin/cmd/refresh_cache.lua b/src/luarocks/admin/cmd/refresh_cache.lua index 947dbfb0..3ffe56d9 100644 --- a/src/luarocks/admin/cmd/refresh_cache.lua +++ b/src/luarocks/admin/cmd/refresh_cache.lua @@ -18,7 +18,7 @@ function refresh_cache.command(flags) if not server then return nil, upload_server end local download_url = cache.get_server_urls(server, upload_server) - local ok, err = cache.refresh_local_cache(server, download_url, cfg.upload_user, cfg.upload_password) + local ok, err = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) if not ok then return nil, err else diff --git a/src/luarocks/admin/cmd/remove.lua b/src/luarocks/admin/cmd/remove.lua index 173cc1a9..f005c83c 100644 --- a/src/luarocks/admin/cmd/remove.lua +++ b/src/luarocks/admin/cmd/remove.lua @@ -32,7 +32,7 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve local at = fs.current_dir() local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url - local local_cache, protocol, server_path, user, password = refresh_fn(server, download_url, cfg.upload_user, cfg.upload_password) + local local_cache, protocol, server_path, user, password = refresh_fn(download_url, cfg.upload_user, cfg.upload_password) if not local_cache then return nil, protocol end diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 85c83744..7fdefce0 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -98,6 +98,7 @@ local supported_flags = { ["help"] = true, ["home"] = true, ["homepage"] = "\"\"", + ["index"] = true, ["issues"] = true, ["keep"] = true, ["labels"] = true, -- cgit v1.2.3-55-g6feb