diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2016-10-29 15:56:26 -0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-29 15:56:26 -0200 |
| commit | d9437bb79499c25751c304ee684c5de8fbfa1d73 (patch) | |
| tree | ac82dd9a019ac861eec113cdc729acf71c2889d2 /src | |
| parent | f04b02b27fac9c409d0da5628026648f8329a99b (diff) | |
| parent | 7ce4a5c9accb22eb1fc422036c72f809e8c026b9 (diff) | |
| download | luarocks-d9437bb79499c25751c304ee684c5de8fbfa1d73.tar.gz luarocks-d9437bb79499c25751c304ee684c5de8fbfa1d73.tar.bz2 luarocks-d9437bb79499c25751c304ee684c5de8fbfa1d73.zip | |
Merge pull request #638 from mpeterv/remove-without-manifest-rebuild
Remove packages without manifest rebuild
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/manif.lua | 182 | ||||
| -rw-r--r-- | src/luarocks/repos.lua | 4 |
2 files changed, 122 insertions, 64 deletions
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 2d983a85..c4c52bd2 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -161,31 +161,59 @@ function manif.load_manifest(repo_url, lua_version) | |||
| 161 | return manif_core.manifest_loader(pathname, repo_url, lua_version) | 161 | return manif_core.manifest_loader(pathname, repo_url, lua_version) |
| 162 | end | 162 | end |
| 163 | 163 | ||
| 164 | --- Output a table listing items of a package. | 164 | --- Update storage table to account for items provided by a package. |
| 165 | -- @param itemsfn function: a function for obtaining items of a package. | 165 | -- @param storage table: a table storing items in the following format: |
| 166 | -- pkg and version will be passed to it; it should return a table with | 166 | -- keys are item names and values are arrays of packages providing each item, |
| 167 | -- items as keys. | 167 | -- where a package is specified as string `name/version`. |
| 168 | -- @param pkg string: package name | 168 | -- @param items table: a table mapping item names to paths. |
| 169 | -- @param version string: package version | 169 | -- @param name string: package name. |
| 170 | -- @param tbl table: the package matching table: keys should be item names | 170 | -- @param version string: package version. |
| 171 | -- and values arrays of strings with packages names in "name/version" format. | 171 | local function store_package_items(storage, name, version, items) |
| 172 | local function store_package_items(itemsfn, pkg, version, tbl) | 172 | assert(type(storage) == "table") |
| 173 | assert(type(itemsfn) == "function") | 173 | assert(type(items) == "table") |
| 174 | assert(type(pkg) == "string") | 174 | assert(type(name) == "string") |
| 175 | assert(type(version) == "string") | 175 | assert(type(version) == "string") |
| 176 | assert(type(tbl) == "table") | ||
| 177 | 176 | ||
| 178 | local pkg_version = pkg.."/"..version | 177 | local package_identifier = name.."/"..version |
| 179 | local result = {} | ||
| 180 | 178 | ||
| 181 | for item, path in pairs(itemsfn(pkg, version)) do | 179 | for item_name, path in pairs(items) do |
| 182 | result[item] = path | 180 | if not storage[item_name] then |
| 183 | if not tbl[item] then | 181 | storage[item_name] = {} |
| 184 | tbl[item] = {} | 182 | end |
| 183 | |||
| 184 | table.insert(storage[item_name], package_identifier) | ||
| 185 | end | ||
| 186 | end | ||
| 187 | |||
| 188 | --- Update storage table removing items provided by a package. | ||
| 189 | -- @param storage table: a table storing items in the following format: | ||
| 190 | -- keys are item names and values are arrays of packages providing each item, | ||
| 191 | -- where a package is specified as string `name/version`. | ||
| 192 | -- @param items table: a table mapping item names to paths. | ||
| 193 | -- @param name string: package name. | ||
| 194 | -- @param version string: package version. | ||
| 195 | local function remove_package_items(storage, name, version, items) | ||
| 196 | assert(type(storage) == "table") | ||
| 197 | assert(type(items) == "table") | ||
| 198 | assert(type(name) == "string") | ||
| 199 | assert(type(version) == "string") | ||
| 200 | |||
| 201 | local package_identifier = name.."/"..version | ||
| 202 | |||
| 203 | for item_name, path in pairs(items) do | ||
| 204 | local all_identifiers = storage[item_name] | ||
| 205 | |||
| 206 | for i, identifier in ipairs(all_identifiers) do | ||
| 207 | if identifier == package_identifier then | ||
| 208 | table.remove(all_identifiers, i) | ||
| 209 | break | ||
| 210 | end | ||
| 211 | end | ||
| 212 | |||
| 213 | if #all_identifiers == 0 then | ||
| 214 | storage[item_name] = nil | ||
| 185 | end | 215 | end |
| 186 | table.insert(tbl[item], pkg_version) | ||
| 187 | end | 216 | end |
| 188 | return result | ||
| 189 | end | 217 | end |
| 190 | 218 | ||
| 191 | --- Sort function for ordering rock identifiers in a manifest's | 219 | --- Sort function for ordering rock identifiers in a manifest's |
| @@ -321,12 +349,10 @@ end | |||
| 321 | -- @param results table: The search results as returned by search.disk_search. | 349 | -- @param results table: The search results as returned by search.disk_search. |
| 322 | -- @param manifest table: A manifest table (must contain repository, modules, commands tables). | 350 | -- @param manifest table: A manifest table (must contain repository, modules, commands tables). |
| 323 | -- It will be altered to include the search results. | 351 | -- It will be altered to include the search results. |
| 324 | -- @param dep_handler: dependency handler function | ||
| 325 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. | 352 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. |
| 326 | local function store_results(results, manifest, dep_handler) | 353 | local function store_results(results, manifest) |
| 327 | assert(type(results) == "table") | 354 | assert(type(results) == "table") |
| 328 | assert(type(manifest) == "table") | 355 | assert(type(manifest) == "table") |
| 329 | assert((not dep_handler) or type(dep_handler) == "function") | ||
| 330 | 356 | ||
| 331 | for name, versions in pairs(results) do | 357 | for name, versions in pairs(results) do |
| 332 | local pkgtable = manifest.repository[name] or {} | 358 | local pkgtable = manifest.repository[name] or {} |
| @@ -340,8 +366,11 @@ local function store_results(results, manifest, dep_handler) | |||
| 340 | if not rock_manifest then | 366 | if not rock_manifest then |
| 341 | return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" | 367 | return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" |
| 342 | end | 368 | end |
| 343 | entrytable.modules = store_package_items(repos.package_modules, name, version, manifest.modules) | 369 | |
| 344 | entrytable.commands = store_package_items(repos.package_commands, name, version, manifest.commands) | 370 | entrytable.modules = repos.package_modules(name, version) |
| 371 | store_package_items(manifest.modules, name, version, entrytable.modules) | ||
| 372 | entrytable.commands = repos.package_commands(name, version) | ||
| 373 | store_package_items(manifest.commands, name, version, entrytable.commands) | ||
| 345 | end | 374 | end |
| 346 | table.insert(versiontable, entrytable) | 375 | table.insert(versiontable, entrytable) |
| 347 | end | 376 | end |
| @@ -349,9 +378,6 @@ local function store_results(results, manifest, dep_handler) | |||
| 349 | end | 378 | end |
| 350 | manifest.repository[name] = pkgtable | 379 | manifest.repository[name] = pkgtable |
| 351 | end | 380 | end |
| 352 | if dep_handler then | ||
| 353 | dep_handler(manifest) | ||
| 354 | end | ||
| 355 | sort_package_matching_table(manifest.modules) | 381 | sort_package_matching_table(manifest.modules) |
| 356 | sort_package_matching_table(manifest.commands) | 382 | sort_package_matching_table(manifest.commands) |
| 357 | return true | 383 | return true |
| @@ -385,34 +411,26 @@ function manif.make_manifest(repo, deps_mode, remote) | |||
| 385 | 411 | ||
| 386 | manif_core.cache_manifest(repo, nil, manifest) | 412 | manif_core.cache_manifest(repo, nil, manifest) |
| 387 | 413 | ||
| 388 | local dep_handler = nil | 414 | local ok, err = store_results(results, manifest) |
| 389 | if not remote then | ||
| 390 | dep_handler = function(manifest) | ||
| 391 | update_dependencies(manifest, deps_mode) | ||
| 392 | end | ||
| 393 | end | ||
| 394 | local ok, err = store_results(results, manifest, dep_handler) | ||
| 395 | if not ok then return nil, err end | 415 | if not ok then return nil, err end |
| 396 | 416 | ||
| 397 | if remote then | 417 | if remote then |
| 398 | local cache = {} | 418 | local cache = {} |
| 399 | for luaver in util.lua_versions() do | 419 | for luaver in util.lua_versions() do |
| 400 | local vmanifest = { repository = {}, modules = {}, commands = {} } | 420 | local vmanifest = { repository = {}, modules = {}, commands = {} } |
| 401 | local dep_handler = function(manifest) | 421 | local ok, err = store_results(results, vmanifest) |
| 402 | filter_by_lua_version(manifest, luaver, repo, cache) | 422 | filter_by_lua_version(vmanifest, luaver, repo, cache) |
| 403 | end | ||
| 404 | local ok, err = store_results(results, vmanifest, dep_handler) | ||
| 405 | save_table(repo, "manifest-"..luaver, vmanifest) | 423 | save_table(repo, "manifest-"..luaver, vmanifest) |
| 406 | end | 424 | end |
| 425 | else | ||
| 426 | update_dependencies(manifest, deps_mode) | ||
| 407 | end | 427 | end |
| 408 | 428 | ||
| 409 | return save_table(repo, "manifest", manifest) | 429 | return save_table(repo, "manifest", manifest) |
| 410 | end | 430 | end |
| 411 | 431 | ||
| 412 | --- Load a manifest file from a local repository and add to the repository | 432 | --- Update manifest file for a local repository |
| 413 | -- information with regard to the given name and version. | 433 | -- adding information about a version of a package installed in that repository. |
| 414 | -- A file called 'manifest' will be written in the root of the given | ||
| 415 | -- repository directory. | ||
| 416 | -- @param name string: Name of a package from the repository. | 434 | -- @param name string: Name of a package from the repository. |
| 417 | -- @param version string: Version of a package from the repository. | 435 | -- @param version string: Version of a package from the repository. |
| 418 | -- @param repo string or nil: Pathname of a local repository. If not given, | 436 | -- @param repo string or nil: Pathname of a local repository. If not given, |
| @@ -420,38 +438,78 @@ end | |||
| 420 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 438 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, |
| 421 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 439 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
| 422 | -- "none" for using the default dependency mode from the configuration. | 440 | -- "none" for using the default dependency mode from the configuration. |
| 423 | -- @return boolean or (nil, string): True if manifest was generated, | 441 | -- @return boolean or (nil, string): True if manifest was updated successfully, |
| 424 | -- or nil and an error message. | 442 | -- or nil and an error message. |
| 425 | function manif.update_manifest(name, version, repo, deps_mode) | 443 | function manif.add_to_manifest(name, version, repo, deps_mode) |
| 426 | assert(type(name) == "string") | 444 | assert(type(name) == "string") |
| 427 | assert(type(version) == "string") | 445 | assert(type(version) == "string") |
| 428 | repo = path.rocks_dir(repo or cfg.root_dir) | 446 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
| 429 | assert(type(deps_mode) == "string") | 447 | assert(type(deps_mode) == "string") |
| 430 | 448 | ||
| 431 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 449 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
| 432 | 450 | ||
| 433 | local manifest, err = manif.load_manifest(repo) | 451 | local manifest, err = manif_core.load_local_manifest(rocks_dir) |
| 434 | if not manifest then | 452 | if not manifest then |
| 435 | util.printerr("No existing manifest. Attempting to rebuild...") | 453 | util.printerr("No existing manifest. Attempting to rebuild...") |
| 436 | local ok, err = manif.make_manifest(repo, deps_mode) | 454 | -- Manifest built by `manif.make_manifest` should already |
| 437 | if not ok then | 455 | -- include information about given name and version, |
| 438 | return nil, err | 456 | -- no need to update it. |
| 439 | end | 457 | return manif.make_manifest(rocks_dir, deps_mode) |
| 440 | manifest, err = manif.load_manifest(repo) | ||
| 441 | if not manifest then | ||
| 442 | return nil, err | ||
| 443 | end | ||
| 444 | end | 458 | end |
| 445 | 459 | ||
| 446 | local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} | 460 | local results = {[name] = {[version] = {{arch = "installed", repo = rocks_dir}}}} |
| 447 | 461 | ||
| 448 | local dep_handler = function(manifest) | 462 | local ok, err = store_results(results, manifest) |
| 449 | update_dependencies(manifest, deps_mode) | ||
| 450 | end | ||
| 451 | local ok, err = store_results(results, manifest, dep_handler) | ||
| 452 | if not ok then return nil, err end | 463 | if not ok then return nil, err end |
| 453 | 464 | ||
| 454 | return save_table(repo, "manifest", manifest) | 465 | update_dependencies(manifest, deps_mode) |
| 466 | return save_table(rocks_dir, "manifest", manifest) | ||
| 467 | end | ||
| 468 | |||
| 469 | --- Update manifest file for a local repository | ||
| 470 | -- removing information about a version of a package. | ||
| 471 | -- @param name string: Name of a package removed from the repository. | ||
| 472 | -- @param version string: Version of a package removed from the repository. | ||
| 473 | -- @param repo string or nil: Pathname of a local repository. If not given, | ||
| 474 | -- the default local repository is used. | ||
| 475 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | ||
| 476 | -- "all" for all trees, "order" for all trees with priority >= the current default, | ||
| 477 | -- "none" for using the default dependency mode from the configuration. | ||
| 478 | -- @return boolean or (nil, string): True if manifest was updated successfully, | ||
| 479 | -- or nil and an error message. | ||
| 480 | function manif.remove_from_manifest(name, version, repo, deps_mode) | ||
| 481 | assert(type(name) == "string") | ||
| 482 | assert(type(version) == "string") | ||
| 483 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | ||
| 484 | assert(type(deps_mode) == "string") | ||
| 485 | |||
| 486 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | ||
| 487 | |||
| 488 | local manifest, err = manif_core.load_local_manifest(rocks_dir) | ||
| 489 | if not manifest then | ||
| 490 | util.printerr("No existing manifest. Attempting to rebuild...") | ||
| 491 | -- Manifest built by `manif.make_manifest` should already | ||
| 492 | -- include up-to-date information, no need to update it. | ||
| 493 | return manif.make_manifest(rocks_dir, deps_mode) | ||
| 494 | end | ||
| 495 | |||
| 496 | local package_entry = manifest.repository[name] | ||
| 497 | |||
| 498 | local version_entry = package_entry[version][1] | ||
| 499 | remove_package_items(manifest.modules, name, version, version_entry.modules) | ||
| 500 | remove_package_items(manifest.commands, name, version, version_entry.commands) | ||
| 501 | |||
| 502 | package_entry[version] = nil | ||
| 503 | manifest.dependencies[name][version] = nil | ||
| 504 | |||
| 505 | if not next(package_entry) then | ||
| 506 | -- No more versions of this package. | ||
| 507 | manifest.repository[name] = nil | ||
| 508 | manifest.dependencies[name] = nil | ||
| 509 | end | ||
| 510 | |||
| 511 | update_dependencies(manifest, deps_mode) | ||
| 512 | return save_table(rocks_dir, "manifest", manifest) | ||
| 455 | end | 513 | end |
| 456 | 514 | ||
| 457 | function manif.zip_manifests() | 515 | function manif.zip_manifests() |
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index c5f157c4..d4d9694e 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
| @@ -312,7 +312,7 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) | |||
| 312 | return nil, err | 312 | return nil, err |
| 313 | end | 313 | end |
| 314 | 314 | ||
| 315 | return manif.update_manifest(name, version, nil, deps_mode) | 315 | return manif.add_to_manifest(name, version, nil, deps_mode) |
| 316 | end | 316 | end |
| 317 | 317 | ||
| 318 | --- Delete a package from the local repository. | 318 | --- Delete a package from the local repository. |
| @@ -398,7 +398,7 @@ function repos.delete_version(name, version, deps_mode, quick) | |||
| 398 | return true | 398 | return true |
| 399 | end | 399 | end |
| 400 | 400 | ||
| 401 | return manif.make_manifest(cfg.rocks_dir, deps_mode) | 401 | return manif.remove_from_manifest(name, version, nil, deps_mode) |
| 402 | end | 402 | end |
| 403 | 403 | ||
| 404 | return repos | 404 | return repos |
