diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:06 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | fe5fd343626e065b170c2f0f7fbe9f76fee5daec (patch) | |
| tree | c7b6312342cbaa263e0b25b20f3bf7cb4ef3b935 /src | |
| parent | 3ebe7058f649bb0045e844ba0c119ac9dd445d9b (diff) | |
| download | luarocks-fe5fd343626e065b170c2f0f7fbe9f76fee5daec.tar.gz luarocks-fe5fd343626e065b170c2f0f7fbe9f76fee5daec.tar.bz2 luarocks-fe5fd343626e065b170c2f0f7fbe9f76fee5daec.zip | |
Teal: convert luarocks.repos
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/repos.tl (renamed from src/luarocks/repos.lua) | 205 |
1 files changed, 99 insertions, 106 deletions
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.tl index 764fe3ad..46458607 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.tl | |||
| @@ -1,6 +1,20 @@ | |||
| 1 | 1 | ||
| 2 | --- Functions for managing the repository on disk. | 2 | --- Functions for managing the repository on disk. |
| 3 | local repos = {} | 3 | local record repos |
| 4 | record Op | ||
| 5 | name: string | ||
| 6 | dst: string | ||
| 7 | backup: boolean | ||
| 8 | src: string | ||
| 9 | suffix: string | ||
| 10 | backup_file: string | ||
| 11 | fn: function(string, string, boolean): boolean, string | ||
| 12 | end | ||
| 13 | record Paths | ||
| 14 | nv: string | ||
| 15 | v: string | ||
| 16 | end | ||
| 17 | end | ||
| 4 | 18 | ||
| 5 | local fs = require("luarocks.fs") | 19 | local fs = require("luarocks.fs") |
| 6 | local path = require("luarocks.path") | 20 | local path = require("luarocks.path") |
| @@ -10,19 +24,15 @@ local dir = require("luarocks.dir") | |||
| 10 | local manif = require("luarocks.manif") | 24 | local manif = require("luarocks.manif") |
| 11 | local vers = require("luarocks.core.vers") | 25 | local vers = require("luarocks.core.vers") |
| 12 | 26 | ||
| 13 | local unpack = unpack or table.unpack -- luacheck: ignore 211 | 27 | local type RockManifest = require("luarocks.core.types.rockmanifest").RockManifest |
| 14 | 28 | local type Entry = RockManifest.Entry | |
| 15 | --- Get type and name of an item (a module or a command) provided by a file. | 29 | |
| 16 | -- @param deploy_type string: rock manifest subtree the file comes from ("bin", "lua", or "lib"). | 30 | local type Rockspec = require("luarocks.core.types.rockspec").Rockspec |
| 17 | -- @param file_path string: path to the file relatively to deploy_type subdirectory. | 31 | |
| 18 | -- @return (string, string): item type ("module" or "command") and name. | 32 | local type Tree = require("luarocks.core.types.tree").Tree |
| 19 | local function get_provided_item(deploy_type, file_path) | 33 | |
| 20 | assert(type(deploy_type) == "string") | 34 | local type Op = repos.Op |
| 21 | assert(type(file_path) == "string") | 35 | local type Paths = repos.Paths |
| 22 | local item_type = deploy_type == "bin" and "command" or "module" | ||
| 23 | local item_name = item_type == "command" and file_path or path.path_to_module(file_path) | ||
| 24 | return item_type, item_name | ||
| 25 | end | ||
| 26 | 36 | ||
| 27 | -- Tree of files installed by a package are stored | 37 | -- Tree of files installed by a package are stored |
| 28 | -- in its rock manifest. Some of these files have to | 38 | -- in its rock manifest. Some of these files have to |
| @@ -45,8 +55,8 @@ end | |||
| 45 | -- @param name string: a package name. | 55 | -- @param name string: a package name. |
| 46 | -- @return table or nil: An array of strings listing installed | 56 | -- @return table or nil: An array of strings listing installed |
| 47 | -- versions of a package, or nil if none is available. | 57 | -- versions of a package, or nil if none is available. |
| 48 | local function get_installed_versions(name) | 58 | local function get_installed_versions(name: string): {string} |
| 49 | assert(type(name) == "string" and not name:match("/")) | 59 | assert(not name:match("/")) |
| 50 | 60 | ||
| 51 | local dirs = fs.list_dir(path.versions_dir(name)) | 61 | local dirs = fs.list_dir(path.versions_dir(name)) |
| 52 | return (dirs and #dirs > 0) and dirs or nil | 62 | return (dirs and #dirs > 0) and dirs or nil |
| @@ -58,27 +68,24 @@ end | |||
| 58 | -- @param version string: package version in string format | 68 | -- @param version string: package version in string format |
| 59 | -- @return boolean: true if a package is installed, | 69 | -- @return boolean: true if a package is installed, |
| 60 | -- false otherwise. | 70 | -- false otherwise. |
| 61 | function repos.is_installed(name, version) | 71 | function repos.is_installed(name: string, version: string): boolean |
| 62 | assert(type(name) == "string" and not name:match("/")) | 72 | assert(not name:match("/")) |
| 63 | assert(type(version) == "string") | ||
| 64 | 73 | ||
| 65 | return fs.is_dir(path.install_dir(name, version)) | 74 | return fs.is_dir(path.install_dir(name, version)) |
| 66 | end | 75 | end |
| 67 | 76 | ||
| 68 | function repos.recurse_rock_manifest_entry(entry, action) | 77 | function repos.recurse_rock_manifest_entry(entry: Entry, action: (function(string): boolean, string)): boolean, string |
| 69 | assert(type(action) == "function") | ||
| 70 | |||
| 71 | if entry == nil then | 78 | if entry == nil then |
| 72 | return true | 79 | return true |
| 73 | end | 80 | end |
| 74 | 81 | ||
| 75 | local function do_recurse_rock_manifest_entry(tree, parent_path) | 82 | local function do_recurse_rock_manifest_entry(tree: Entry, parent_path?: string): boolean, string |
| 76 | 83 | ||
| 77 | for file, sub in pairs(tree) do | 84 | for file, sub in pairs(tree as {string: any}) do --! |
| 78 | local sub_path = (parent_path and (parent_path .. "/") or "") .. file | 85 | local sub_path = (parent_path and (parent_path .. "/") or "") .. file |
| 79 | local ok, err -- luacheck: ignore 231 | 86 | local ok, err: boolean, string -- luacheck: ignore 231 |
| 80 | 87 | ||
| 81 | if type(sub) == "table" then | 88 | if sub is Entry then |
| 82 | ok, err = do_recurse_rock_manifest_entry(sub, sub_path) | 89 | ok, err = do_recurse_rock_manifest_entry(sub, sub_path) |
| 83 | else | 90 | else |
| 84 | ok, err = action(sub_path) | 91 | ok, err = action(sub_path) |
| @@ -91,10 +98,10 @@ function repos.recurse_rock_manifest_entry(entry, action) | |||
| 91 | return do_recurse_rock_manifest_entry(entry) | 98 | return do_recurse_rock_manifest_entry(entry) |
| 92 | end | 99 | end |
| 93 | 100 | ||
| 94 | local function store_package_data(result, rock_manifest, deploy_type) | 101 | local function store_package_data(result: {string: string}, rock_manifest: {string : Entry}, deploy_type: string) |
| 95 | if rock_manifest[deploy_type] then | 102 | if rock_manifest[deploy_type] then |
| 96 | repos.recurse_rock_manifest_entry(rock_manifest[deploy_type], function(file_path) | 103 | repos.recurse_rock_manifest_entry(rock_manifest[deploy_type], function(file_path: string): boolean, string |
| 97 | local _, item_name = get_provided_item(deploy_type, file_path) | 104 | local _, item_name = manif.get_provided_item(deploy_type, file_path) |
| 98 | result[item_name] = file_path | 105 | result[item_name] = file_path |
| 99 | return true | 106 | return true |
| 100 | end) | 107 | end) |
| @@ -110,9 +117,8 @@ end | |||
| 110 | -- relative to "lib" or "lua" rock manifest subtree. | 117 | -- relative to "lib" or "lua" rock manifest subtree. |
| 111 | -- If no modules are found or if package name or version | 118 | -- If no modules are found or if package name or version |
| 112 | -- are invalid, an empty table is returned. | 119 | -- are invalid, an empty table is returned. |
| 113 | function repos.package_modules(name, version) | 120 | function repos.package_modules(name: string, version: string): {string: string} |
| 114 | assert(type(name) == "string" and not name:match("/")) | 121 | assert(not name:match("/")) |
| 115 | assert(type(version) == "string") | ||
| 116 | 122 | ||
| 117 | local result = {} | 123 | local result = {} |
| 118 | local rock_manifest = manif.load_rock_manifest(name, version) | 124 | local rock_manifest = manif.load_rock_manifest(name, version) |
| @@ -131,9 +137,8 @@ end | |||
| 131 | -- relative to "bin" rock manifest subtree. | 137 | -- relative to "bin" rock manifest subtree. |
| 132 | -- If no commands are found or if package name or version | 138 | -- If no commands are found or if package name or version |
| 133 | -- are invalid, an empty table is returned. | 139 | -- are invalid, an empty table is returned. |
| 134 | function repos.package_commands(name, version) | 140 | function repos.package_commands(name: string, version: string): {string: string} |
| 135 | assert(type(name) == "string" and not name:match("/")) | 141 | assert(not name:match("/")) |
| 136 | assert(type(version) == "string") | ||
| 137 | 142 | ||
| 138 | local result = {} | 143 | local result = {} |
| 139 | local rock_manifest = manif.load_rock_manifest(name, version) | 144 | local rock_manifest = manif.load_rock_manifest(name, version) |
| @@ -148,13 +153,16 @@ end | |||
| 148 | -- @param version string: version of an installed rock | 153 | -- @param version string: version of an installed rock |
| 149 | -- @return boolean: returns true if rock contains platform-specific | 154 | -- @return boolean: returns true if rock contains platform-specific |
| 150 | -- binary executables, or false if it is a pure-Lua rock. | 155 | -- binary executables, or false if it is a pure-Lua rock. |
| 151 | function repos.has_binaries(name, version) | 156 | function repos.has_binaries(name: string, version: string): boolean |
| 152 | assert(type(name) == "string" and not name:match("/")) | 157 | assert(not name:match("/")) |
| 153 | assert(type(version) == "string") | ||
| 154 | 158 | ||
| 155 | local rock_manifest = manif.load_rock_manifest(name, version) | 159 | local entries = manif.load_rock_manifest(name, version) |
| 156 | if rock_manifest and rock_manifest.bin then | 160 | if not entries then |
| 157 | for bin_name, md5 in pairs(rock_manifest.bin) do | 161 | return false |
| 162 | end | ||
| 163 | local bin = entries["bin"] | ||
| 164 | if bin is {string:Entry} then | ||
| 165 | for bin_name, md5 in pairs(bin) do | ||
| 158 | -- TODO verify that it is the same file. If it isn't, find the actual command. | 166 | -- TODO verify that it is the same file. If it isn't, find the actual command. |
| 159 | if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, bin_name)) then | 167 | if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, bin_name)) then |
| 160 | return true | 168 | return true |
| @@ -164,9 +172,7 @@ function repos.has_binaries(name, version) | |||
| 164 | return false | 172 | return false |
| 165 | end | 173 | end |
| 166 | 174 | ||
| 167 | function repos.run_hook(rockspec, hook_name) | 175 | function repos.run_hook(rockspec: Rockspec, hook_name: string): boolean, string |
| 168 | assert(rockspec:type() == "rockspec") | ||
| 169 | assert(type(hook_name) == "string") | ||
| 170 | 176 | ||
| 171 | local hooks = rockspec.hooks | 177 | local hooks = rockspec.hooks |
| 172 | if not hooks then | 178 | if not hooks then |
| @@ -178,10 +184,10 @@ function repos.run_hook(rockspec, hook_name) | |||
| 178 | end | 184 | end |
| 179 | 185 | ||
| 180 | if not hooks.substituted_variables then | 186 | if not hooks.substituted_variables then |
| 181 | util.variable_substitutions(hooks, rockspec.variables) | 187 | util.variable_substitutions(hooks as {string: string}, rockspec.variables) |
| 182 | hooks.substituted_variables = true | 188 | hooks.substituted_variables = true |
| 183 | end | 189 | end |
| 184 | local hook = hooks[hook_name] | 190 | local hook = (hooks as {string: string})[hook_name] |
| 185 | if hook then | 191 | if hook then |
| 186 | util.printout(hook) | 192 | util.printout(hook) |
| 187 | if not fs.execute(hook) then | 193 | if not fs.execute(hook) then |
| @@ -191,10 +197,9 @@ function repos.run_hook(rockspec, hook_name) | |||
| 191 | return true | 197 | return true |
| 192 | end | 198 | end |
| 193 | 199 | ||
| 194 | function repos.should_wrap_bin_scripts(rockspec) | 200 | function repos.should_wrap_bin_scripts(rockspec: Rockspec): boolean |
| 195 | assert(rockspec:type() == "rockspec") | ||
| 196 | 201 | ||
| 197 | if cfg.wrap_bin_scripts ~= nil then | 202 | if cfg.wrap_bin_scripts then |
| 198 | return cfg.wrap_bin_scripts | 203 | return cfg.wrap_bin_scripts |
| 199 | end | 204 | end |
| 200 | if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then | 205 | if rockspec.deploy and rockspec.deploy.wrap_bin_scripts == false then |
| @@ -203,7 +208,7 @@ function repos.should_wrap_bin_scripts(rockspec) | |||
| 203 | return true | 208 | return true |
| 204 | end | 209 | end |
| 205 | 210 | ||
| 206 | local function find_suffixed(file, suffix) | 211 | local function find_suffixed(file: string, suffix: string): string, string |
| 207 | local filenames = {file} | 212 | local filenames = {file} |
| 208 | if suffix and suffix ~= "" then | 213 | if suffix and suffix ~= "" then |
| 209 | table.insert(filenames, 1, file .. suffix) | 214 | table.insert(filenames, 1, file .. suffix) |
| @@ -218,7 +223,7 @@ local function find_suffixed(file, suffix) | |||
| 218 | return nil, table.concat(filenames, ", ") .. " not found" | 223 | return nil, table.concat(filenames, ", ") .. " not found" |
| 219 | end | 224 | end |
| 220 | 225 | ||
| 221 | local function check_suffix(filename, suffix) | 226 | local function check_suffix(filename: string, suffix: string): string |
| 222 | local suffixed_filename, err = find_suffixed(filename, suffix) | 227 | local suffixed_filename, err = find_suffixed(filename, suffix) |
| 223 | if not suffixed_filename then | 228 | if not suffixed_filename then |
| 224 | return "" | 229 | return "" |
| @@ -232,21 +237,17 @@ end | |||
| 232 | -- item from the newest version of lexicographically smallest package | 237 | -- item from the newest version of lexicographically smallest package |
| 233 | -- is deployed using non-versioned name and others use versioned names. | 238 | -- is deployed using non-versioned name and others use versioned names. |
| 234 | 239 | ||
| 235 | local function get_deploy_paths(name, version, deploy_type, file_path, repo) | 240 | local function get_deploy_paths(name: string, version: string, deploy_type: string, file_path: string, repo?: string | Tree): Paths |
| 236 | assert(type(name) == "string") | ||
| 237 | assert(type(version) == "string") | ||
| 238 | assert(type(deploy_type) == "string") | ||
| 239 | assert(type(file_path) == "string") | ||
| 240 | 241 | ||
| 241 | repo = repo or cfg.root_dir | 242 | repo = repo or cfg.root_dir |
| 242 | local deploy_dir = path["deploy_" .. deploy_type .. "_dir"](repo) | 243 | local deploy_dir = (path as {string: function(string | Tree): string})["deploy_" .. deploy_type .. "_dir"](repo) |
| 243 | local non_versioned = dir.path(deploy_dir, file_path) | 244 | local non_versioned = dir.path(deploy_dir, file_path) |
| 244 | local versioned = path.versioned_name(non_versioned, deploy_dir, name, version) | 245 | local versioned = path.versioned_name(non_versioned, deploy_dir, name, version) |
| 245 | return { nv = non_versioned, v = versioned } | 246 | return { nv = non_versioned, v = versioned } |
| 246 | end | 247 | end |
| 247 | 248 | ||
| 248 | local function check_spot_if_available(name, version, deploy_type, file_path) | 249 | local function check_spot_if_available(name: string, version: string, deploy_type: string, file_path: string): string, string, string, string |
| 249 | local item_type, item_name = get_provided_item(deploy_type, file_path) | 250 | local item_type, item_name = manif.get_provided_item(deploy_type, file_path) |
| 250 | local cur_name, cur_version = manif.get_current_provider(item_type, item_name) | 251 | local cur_name, cur_version = manif.get_current_provider(item_type, item_name) |
| 251 | 252 | ||
| 252 | -- older versions of LuaRocks (< 3) registered "foo.init" files as "foo" | 253 | -- older versions of LuaRocks (< 3) registered "foo.init" files as "foo" |
| @@ -267,7 +268,7 @@ local function check_spot_if_available(name, version, deploy_type, file_path) | |||
| 267 | end | 268 | end |
| 268 | end | 269 | end |
| 269 | 270 | ||
| 270 | local function backup_existing(should_backup, target) | 271 | local function backup_existing(should_backup: boolean, target: string): string, string |
| 271 | if not should_backup then | 272 | if not should_backup then |
| 272 | fs.delete(target) | 273 | fs.delete(target) |
| 273 | return | 274 | return |
| @@ -287,11 +288,11 @@ local function backup_existing(should_backup, target) | |||
| 287 | end | 288 | end |
| 288 | end | 289 | end |
| 289 | 290 | ||
| 290 | local function prepare_op_install() | 291 | local function prepare_op_install(): function(Op): (boolean, string), function() |
| 291 | local mkdirs = {} | 292 | local mkdirs = {} |
| 292 | local rmdirs = {} | 293 | local rmdirs = {} |
| 293 | 294 | ||
| 294 | local function memoize_mkdir(d) | 295 | local function memoize_mkdir(d: string): boolean, string |
| 295 | if mkdirs[d] then | 296 | if mkdirs[d] then |
| 296 | return true | 297 | return true |
| 297 | end | 298 | end |
| @@ -303,7 +304,7 @@ local function prepare_op_install() | |||
| 303 | return true | 304 | return true |
| 304 | end | 305 | end |
| 305 | 306 | ||
| 306 | local function op_install(op) | 307 | local function op_install(op: Op): boolean, string |
| 307 | local ok, err = memoize_mkdir(dir.dir_name(op.dst)) | 308 | local ok, err = memoize_mkdir(dir.dir_name(op.dst)) |
| 308 | if not ok then | 309 | if not ok then |
| 309 | return nil, err | 310 | return nil, err |
| @@ -335,7 +336,7 @@ local function prepare_op_install() | |||
| 335 | return op_install, done_op_install | 336 | return op_install, done_op_install |
| 336 | end | 337 | end |
| 337 | 338 | ||
| 338 | local function rollback_install(op) | 339 | local function rollback_install(op: Op): boolean, string |
| 339 | fs.delete(op.dst) | 340 | fs.delete(op.dst) |
| 340 | if op.backup_file then | 341 | if op.backup_file then |
| 341 | os.rename(op.backup_file, op.dst) | 342 | os.rename(op.backup_file, op.dst) |
| @@ -344,7 +345,7 @@ local function rollback_install(op) | |||
| 344 | return true | 345 | return true |
| 345 | end | 346 | end |
| 346 | 347 | ||
| 347 | local function op_rename(op) | 348 | local function op_rename(op: Op): boolean, string |
| 348 | if op.suffix then | 349 | if op.suffix then |
| 349 | local suffix = check_suffix(op.src, op.suffix) | 350 | local suffix = check_suffix(op.src, op.suffix) |
| 350 | op.src = op.src .. suffix | 351 | op.src = op.src .. suffix |
| @@ -362,13 +363,13 @@ local function op_rename(op) | |||
| 362 | end | 363 | end |
| 363 | end | 364 | end |
| 364 | 365 | ||
| 365 | local function rollback_rename(op) | 366 | local function rollback_rename(op: Op): boolean, string |
| 366 | return op_rename({ src = op.dst, dst = op.src }) | 367 | return op_rename({ src = op.dst, dst = op.src }) |
| 367 | end | 368 | end |
| 368 | 369 | ||
| 369 | local function prepare_op_delete() | 370 | local function prepare_op_delete(): function(Op), function() |
| 370 | local deletes = {} | 371 | local deletes: {string} = {} |
| 371 | local rmdirs = {} | 372 | local rmdirs: {string: boolean} = {} |
| 372 | 373 | ||
| 373 | local function done_op_delete() | 374 | local function done_op_delete() |
| 374 | for _, f in ipairs(deletes) do | 375 | for _, f in ipairs(deletes) do |
| @@ -380,7 +381,7 @@ local function prepare_op_delete() | |||
| 380 | end | 381 | end |
| 381 | end | 382 | end |
| 382 | 383 | ||
| 383 | local function op_delete(op) | 384 | local function op_delete(op: Op) |
| 384 | if op.suffix then | 385 | if op.suffix then |
| 385 | local suffix = check_suffix(op.name, op.suffix) | 386 | local suffix = check_suffix(op.name, op.suffix) |
| 386 | op.name = op.name .. suffix | 387 | op.name = op.name .. suffix |
| @@ -394,19 +395,19 @@ local function prepare_op_delete() | |||
| 394 | return op_delete, done_op_delete | 395 | return op_delete, done_op_delete |
| 395 | end | 396 | end |
| 396 | 397 | ||
| 397 | local function rollback_ops(ops, op_fn, n) | 398 | local function rollback_ops(ops: {Op}, op_fn: function(Op): (boolean, string), n: integer) |
| 398 | for i = 1, n do | 399 | for i = 1, n do |
| 399 | op_fn(ops[i]) | 400 | op_fn(ops[i]) |
| 400 | end | 401 | end |
| 401 | end | 402 | end |
| 402 | 403 | ||
| 403 | --- Double check that all files referenced in `rock_manifest` are installed in `repo`. | 404 | --- Double check that all files referenced in `rock_manifest` are installed in `repo`. |
| 404 | function repos.check_everything_is_installed(name, version, rock_manifest, repo, accept_versioned) | 405 | function repos.check_everything_is_installed(name: string, version: string, rock_manifest: {string: Entry}, repo: string | Tree, accept_versioned: boolean): boolean, string |
| 405 | local missing = {} | 406 | local missing = {} |
| 406 | local suffix = cfg.wrapper_suffix or "" | 407 | local suffix = cfg.wrapper_suffix or "" |
| 407 | for _, category in ipairs({"bin", "lua", "lib"}) do | 408 | for _, category in ipairs({"bin", "lua", "lib"}) do |
| 408 | if rock_manifest[category] then | 409 | if rock_manifest[category] then |
| 409 | repos.recurse_rock_manifest_entry(rock_manifest[category], function(file_path) | 410 | repos.recurse_rock_manifest_entry(rock_manifest[category], function(file_path: string): boolean, string |
| 410 | local paths = get_deploy_paths(name, version, category, file_path, repo) | 411 | local paths = get_deploy_paths(name, version, category, file_path, repo) |
| 411 | if category == "bin" then | 412 | if category == "bin" then |
| 412 | if (fs.exists(paths.nv) or fs.exists(paths.nv .. suffix)) | 413 | if (fs.exists(paths.nv) or fs.exists(paths.nv .. suffix)) |
| @@ -437,19 +438,17 @@ end | |||
| 437 | -- @param deps_mode: string: Which trees to check dependencies for: | 438 | -- @param deps_mode: string: Which trees to check dependencies for: |
| 438 | -- "one" for the current default tree, "all" for all trees, | 439 | -- "one" for the current default tree, "all" for all trees, |
| 439 | -- "order" for all trees with priority >= the current default, "none" for no trees. | 440 | -- "order" for all trees with priority >= the current default, "none" for no trees. |
| 440 | function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | 441 | function repos.deploy_local_files(name: string, version: string, wrap_bin_scripts: boolean, deps_mode: string): boolean, string |
| 441 | assert(type(name) == "string" and not name:match("/")) | 442 | assert(not name:match("/")) |
| 442 | assert(type(version) == "string") | ||
| 443 | assert(type(wrap_bin_scripts) == "boolean") | ||
| 444 | 443 | ||
| 445 | local rock_manifest, load_err = manif.load_rock_manifest(name, version) | 444 | local rock_manifest, load_err = manif.load_rock_manifest(name, version) |
| 446 | if not rock_manifest then return nil, load_err end | 445 | if not rock_manifest then return nil, load_err end |
| 447 | 446 | ||
| 448 | local repo = cfg.root_dir | 447 | local repo = cfg.root_dir |
| 449 | local renames = {} | 448 | local renames: {Op} = {} |
| 450 | local installs = {} | 449 | local installs: {Op} = {} |
| 451 | 450 | ||
| 452 | local function install_binary(source, target) | 451 | local function install_binary(source: string, target: string): boolean, string |
| 453 | if wrap_bin_scripts and fs.is_lua(source) then | 452 | if wrap_bin_scripts and fs.is_lua(source) then |
| 454 | return fs.wrap_script(source, target, deps_mode, name, version) | 453 | return fs.wrap_script(source, target, deps_mode, name, version) |
| 455 | else | 454 | else |
| @@ -457,17 +456,17 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
| 457 | end | 456 | end |
| 458 | end | 457 | end |
| 459 | 458 | ||
| 460 | local function move_lua(source, target) | 459 | local function move_lua(source: string, target: string): boolean, string |
| 461 | return fs.move(source, target, "read") | 460 | return fs.move(source, target, "read") |
| 462 | end | 461 | end |
| 463 | 462 | ||
| 464 | local function move_lib(source, target) | 463 | local function move_lib(source: string, target: string): boolean, string |
| 465 | return fs.move(source, target, "exec") | 464 | return fs.move(source, target, "exec") |
| 466 | end | 465 | end |
| 467 | 466 | ||
| 468 | if rock_manifest.bin then | 467 | if rock_manifest.bin then |
| 469 | local source_dir = path.bin_dir(name, version) | 468 | local source_dir = path.bin_dir(name, version) |
| 470 | repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path) | 469 | repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path: string): boolean, string |
| 471 | local source = dir.path(source_dir, file_path) | 470 | local source = dir.path(source_dir, file_path) |
| 472 | local paths = get_deploy_paths(name, version, "bin", file_path, repo) | 471 | local paths = get_deploy_paths(name, version, "bin", file_path, repo) |
| 473 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "bin", file_path) | 472 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "bin", file_path) |
| @@ -487,7 +486,7 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
| 487 | 486 | ||
| 488 | if rock_manifest.lua then | 487 | if rock_manifest.lua then |
| 489 | local source_dir = path.lua_dir(name, version) | 488 | local source_dir = path.lua_dir(name, version) |
| 490 | repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path) | 489 | repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path: string): boolean, string |
| 491 | local source = dir.path(source_dir, file_path) | 490 | local source = dir.path(source_dir, file_path) |
| 492 | local paths = get_deploy_paths(name, version, "lua", file_path, repo) | 491 | local paths = get_deploy_paths(name, version, "lua", file_path, repo) |
| 493 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lua", file_path) | 492 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lua", file_path) |
| @@ -506,7 +505,7 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
| 506 | 505 | ||
| 507 | if rock_manifest.lib then | 506 | if rock_manifest.lib then |
| 508 | local source_dir = path.lib_dir(name, version) | 507 | local source_dir = path.lib_dir(name, version) |
| 509 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path) | 508 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path: string): boolean, string |
| 510 | local source = dir.path(source_dir, file_path) | 509 | local source = dir.path(source_dir, file_path) |
| 511 | local paths = get_deploy_paths(name, version, "lib", file_path, repo) | 510 | local paths = get_deploy_paths(name, version, "lib", file_path, repo) |
| 512 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lib", file_path) | 511 | local mode, cur_name, cur_version = check_spot_if_available(name, version, "lib", file_path) |
| @@ -546,17 +545,16 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
| 546 | return nil, err | 545 | return nil, err |
| 547 | end | 546 | end |
| 548 | 547 | ||
| 549 | local writer = require("luarocks.manif.writer") | 548 | return true |
| 550 | return writer.add_to_manifest(name, version, nil, deps_mode) | ||
| 551 | end | 549 | end |
| 552 | 550 | ||
| 553 | local function add_to_double_checks(double_checks, name, version) | 551 | local function add_to_double_checks(double_checks: {string: {string: boolean}}, name: string, version: string) |
| 554 | double_checks[name] = double_checks[name] or {} | 552 | double_checks[name] = double_checks[name] or {} |
| 555 | double_checks[name][version] = true | 553 | double_checks[name][version] = true |
| 556 | end | 554 | end |
| 557 | 555 | ||
| 558 | local function double_check_all(double_checks, repo) | 556 | local function double_check_all(double_checks: {string: {string: boolean}}, repo: string | Tree): boolean, string |
| 559 | local errs = {} | 557 | local errs: {string} = {} |
| 560 | for next_name, versions in pairs(double_checks) do | 558 | for next_name, versions in pairs(double_checks) do |
| 561 | for next_version in pairs(versions) do | 559 | for next_version in pairs(versions) do |
| 562 | local rock_manifest, load_err = manif.load_rock_manifest(next_name, next_version) | 560 | local rock_manifest, load_err = manif.load_rock_manifest(next_name, next_version) |
| @@ -582,19 +580,15 @@ end | |||
| 582 | -- of another version that provides the same module that | 580 | -- of another version that provides the same module that |
| 583 | -- was deleted. This is used during 'purge', as every module | 581 | -- was deleted. This is used during 'purge', as every module |
| 584 | -- will be eventually deleted. | 582 | -- will be eventually deleted. |
| 585 | function repos.delete_version(name, version, deps_mode, quick) | 583 | function repos.delete_local_version(name: string, version: string, deps_mode: string, quick: boolean): boolean, string, string |
| 586 | assert(type(name) == "string" and not name:match("/")) | 584 | assert(not name:match("/")) |
| 587 | assert(type(version) == "string") | ||
| 588 | assert(type(deps_mode) == "string") | ||
| 589 | 585 | ||
| 590 | local rock_manifest, load_err = manif.load_rock_manifest(name, version) | 586 | local rock_manifest, load_err = manif.load_rock_manifest(name, version) |
| 591 | if not rock_manifest then | 587 | if not rock_manifest then |
| 592 | if not quick then | 588 | if not quick then |
| 593 | local writer = require("luarocks.manif.writer") | 589 | return nil, "rock_manifest file not found for "..name.." "..version.." - removed entry from the manifest", "remove" |
| 594 | writer.remove_from_manifest(name, version, nil, deps_mode) | ||
| 595 | return nil, "rock_manifest file not found for "..name.." "..version.." - removed entry from the manifest" | ||
| 596 | end | 590 | end |
| 597 | return nil, load_err | 591 | return nil, load_err, "fail" |
| 598 | end | 592 | end |
| 599 | 593 | ||
| 600 | local repo = cfg.root_dir | 594 | local repo = cfg.root_dir |
| @@ -604,7 +598,7 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
| 604 | local double_checks = {} | 598 | local double_checks = {} |
| 605 | 599 | ||
| 606 | if rock_manifest.bin then | 600 | if rock_manifest.bin then |
| 607 | repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path) | 601 | repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path: string): boolean, string |
| 608 | local paths = get_deploy_paths(name, version, "bin", file_path, repo) | 602 | local paths = get_deploy_paths(name, version, "bin", file_path, repo) |
| 609 | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "bin", file_path) | 603 | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "bin", file_path) |
| 610 | if mode == "v" then | 604 | if mode == "v" then |
| @@ -623,7 +617,7 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
| 623 | end | 617 | end |
| 624 | 618 | ||
| 625 | if rock_manifest.lua then | 619 | if rock_manifest.lua then |
| 626 | repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path) | 620 | repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path: string): boolean, string |
| 627 | local paths = get_deploy_paths(name, version, "lua", file_path, repo) | 621 | local paths = get_deploy_paths(name, version, "lua", file_path, repo) |
| 628 | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lua", file_path) | 622 | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lua", file_path) |
| 629 | if mode == "v" then | 623 | if mode == "v" then |
| @@ -644,7 +638,7 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
| 644 | end | 638 | end |
| 645 | 639 | ||
| 646 | if rock_manifest.lib then | 640 | if rock_manifest.lib then |
| 647 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path) | 641 | repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path: string): boolean, string |
| 648 | local paths = get_deploy_paths(name, version, "lib", file_path, repo) | 642 | local paths = get_deploy_paths(name, version, "lib", file_path, repo) |
| 649 | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lib", file_path) | 643 | local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lib", file_path) |
| 650 | if mode == "v" then | 644 | if mode == "v" then |
| @@ -677,7 +671,7 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
| 677 | 671 | ||
| 678 | local ok, err = double_check_all(double_checks, repo) | 672 | local ok, err = double_check_all(double_checks, repo) |
| 679 | if not ok then | 673 | if not ok then |
| 680 | return nil, err | 674 | return nil, err, "fail" |
| 681 | end | 675 | end |
| 682 | end | 676 | end |
| 683 | 677 | ||
| @@ -687,11 +681,10 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
| 687 | end | 681 | end |
| 688 | 682 | ||
| 689 | if quick then | 683 | if quick then |
| 690 | return true | 684 | return true, nil, "ok" |
| 691 | end | 685 | end |
| 692 | 686 | ||
| 693 | local writer = require("luarocks.manif.writer") | 687 | return true, nil, "remove" |
| 694 | return writer.remove_from_manifest(name, version, nil, deps_mode) | ||
| 695 | end | 688 | end |
| 696 | 689 | ||
| 697 | return repos | 690 | return repos \ No newline at end of file |
