aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/remove.tl (renamed from src/luarocks/remove.lua)25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.tl
index a24b54ba..11d270a9 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.tl
@@ -1,23 +1,28 @@
1local remove = {} 1
2local record remove
3end
2 4
3local search = require("luarocks.search") 5local search = require("luarocks.search")
4local deps = require("luarocks.deps") 6local deps = require("luarocks.deps")
5local fetch = require("luarocks.fetch") 7local fetch = require("luarocks.fetch")
6local repos = require("luarocks.repos") 8local repos = require("luarocks.repos")
9local repo_writer = require("luarocks.repo_writer")
7local path = require("luarocks.path") 10local path = require("luarocks.path")
8local util = require("luarocks.util") 11local util = require("luarocks.util")
9local cfg = require("luarocks.core.cfg") 12local cfg = require("luarocks.core.cfg")
10local manif = require("luarocks.manif") 13local manif = require("luarocks.manif")
11local queries = require("luarocks.queries") 14local queries = require("luarocks.queries")
12 15
16local type Result = require("luarocks.core.types.result").Result
17
13--- Obtain a list of packages that depend on the given set of packages 18--- Obtain a list of packages that depend on the given set of packages
14-- (where all packages of the set are versions of one program). 19-- (where all packages of the set are versions of one program).
15-- @param name string: the name of a program 20-- @param name string: the name of a program
16-- @param versions array of string: the versions to be deleted. 21-- @param versions array of string: the versions to be deleted.
17-- @return array of string: an empty table if no packages depend on any 22-- @return array of string: an empty table if no packages depend on any
18-- of the given list, or an array of strings in "name/version" format. 23-- of the given list, or an array of strings in "name/version" format.
19local function check_dependents(name, versions, deps_mode) 24local function check_dependents(name: string, versions: {string: {Result}}, deps_mode: string): {Result}
20 local dependents = {} 25 local dependents: {Result} = {}
21 26
22 local skip_set = {} 27 local skip_set = {}
23 skip_set[name] = {} 28 skip_set[name] = {}
@@ -33,7 +38,7 @@ local function check_dependents(name, versions, deps_mode)
33 for rock_version, _ in pairs(rock_versions) do 38 for rock_version, _ in pairs(rock_versions) do
34 local rockspec, err = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version)) 39 local rockspec, err = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version))
35 if rockspec then 40 if rockspec then
36 local _, missing = deps.match_deps(rockspec.dependencies, rockspec.rocks_provided, skip_set, deps_mode) 41 local _, missing = deps.match_deps(rockspec.dependencies.queries, rockspec.rocks_provided, deps_mode, skip_set)
37 if missing[name] then 42 if missing[name] then
38 table.insert(dependents, { name = rock_name, version = rock_version }) 43 table.insert(dependents, { name = rock_name, version = rock_version })
39 end 44 end
@@ -51,18 +56,18 @@ end
51-- "one" for the current default tree, "all" for all trees, 56-- "one" for the current default tree, "all" for all trees,
52-- "order" for all trees with priority >= the current default, "none" for no trees. 57-- "order" for all trees with priority >= the current default, "none" for no trees.
53-- @return boolean or (nil, string): true on success or nil and an error message. 58-- @return boolean or (nil, string): true on success or nil and an error message.
54local function delete_versions(name, versions, deps_mode) 59local function delete_versions(name: string, versions: {string: any}, deps_mode: string): boolean, string
55 60
56 for version, _ in pairs(versions) do 61 for version, _ in pairs(versions) do
57 util.printout("Removing "..name.." "..version.."...") 62 util.printout("Removing "..name.." "..version.."...")
58 local ok, err = repos.delete_version(name, version, deps_mode) 63 local ok, err = repo_writer.delete_version(name, version, deps_mode)
59 if not ok then return nil, err end 64 if not ok then return nil, err end
60 end 65 end
61 66
62 return true 67 return true
63end 68end
64 69
65function remove.remove_search_results(results, name, deps_mode, force, fast) 70function remove.remove_search_results(results: {string : {string : {Result}}}, name: string, deps_mode: string, force: boolean, fast: boolean): boolean, string
66 local versions = results[name] 71 local versions = results[name]
67 72
68 local version = next(versions) 73 local version = next(versions)
@@ -71,7 +76,7 @@ function remove.remove_search_results(results, name, deps_mode, force, fast)
71 local dependents = {} 76 local dependents = {}
72 if not fast then 77 if not fast then
73 util.printout("Checking stability of dependencies in the absence of") 78 util.printout("Checking stability of dependencies in the absence of")
74 util.printout(name.." "..table.concat(util.keys(versions), ", ").."...") 79 util.printout(name.." "..table.concat((util.keys(versions) as {string | number}), ", ").."...")
75 util.printout() 80 util.printout()
76 dependents = check_dependents(name, versions, deps_mode) 81 dependents = check_dependents(name, versions, deps_mode)
77 end 82 end
@@ -107,11 +112,11 @@ function remove.remove_search_results(results, name, deps_mode, force, fast)
107 return true 112 return true
108end 113end
109 114
110function remove.remove_other_versions(name, version, force, fast) 115function remove.remove_other_versions(name: string, version: string, force: boolean, fast: boolean): boolean, string, string
111 local results = {} 116 local results = {}
112 local query = queries.new(name, nil, version, false, nil, "~=") 117 local query = queries.new(name, nil, version, false, nil, "~=")
113 search.local_manifest_search(results, cfg.rocks_dir, query) 118 search.local_manifest_search(results, cfg.rocks_dir, query)
114 local warn 119 local warn: string
115 if results[name] then 120 if results[name] then
116 local ok, err = remove.remove_search_results(results, name, cfg.deps_mode, force, fast) 121 local ok, err = remove.remove_search_results(results, name, cfg.deps_mode, force, fast)
117 if not ok then -- downgrade failure to a warning 122 if not ok then -- downgrade failure to a warning