diff options
| author | Peter Melnichenko <mpeterval@gmail.com> | 2016-10-28 18:36:21 +0300 |
|---|---|---|
| committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-10-28 22:38:19 +0300 |
| commit | 7ce4a5c9accb22eb1fc422036c72f809e8c026b9 (patch) | |
| tree | c210cb225c21d61425ecb1379d87591c829e533f /src | |
| parent | fb8a377a8735382921f72cd97bb98a0aef38de72 (diff) | |
| download | luarocks-7ce4a5c9accb22eb1fc422036c72f809e8c026b9.tar.gz luarocks-7ce4a5c9accb22eb1fc422036c72f809e8c026b9.tar.bz2 luarocks-7ce4a5c9accb22eb1fc422036c72f809e8c026b9.zip | |
Update manifest after removal without rebuilding
Rename `manif.update_manifest` to `manif.add_to_manifest`.
Add `manif.remove_from_manifest` that performs reverse action.
Use it in `repos.delete_version` to avoid rebuilding manifest
everytime a package is removed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/manif.lua | 89 | ||||
| -rw-r--r-- | src/luarocks/repos.lua | 4 |
2 files changed, 84 insertions, 9 deletions
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 9213f362..c4c52bd2 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -185,6 +185,37 @@ local function store_package_items(storage, name, version, items) | |||
| 185 | end | 185 | end |
| 186 | end | 186 | end |
| 187 | 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 | ||
| 215 | end | ||
| 216 | end | ||
| 217 | end | ||
| 218 | |||
| 188 | --- Sort function for ordering rock identifiers in a manifest's | 219 | --- Sort function for ordering rock identifiers in a manifest's |
| 189 | -- modules table. Rocks are ordered alphabetically by name, and then | 220 | -- modules table. Rocks are ordered alphabetically by name, and then |
| 190 | -- by version which greater first. | 221 | -- by version which greater first. |
| @@ -398,10 +429,8 @@ function manif.make_manifest(repo, deps_mode, remote) | |||
| 398 | return save_table(repo, "manifest", manifest) | 429 | return save_table(repo, "manifest", manifest) |
| 399 | end | 430 | end |
| 400 | 431 | ||
| 401 | --- Load a manifest file from a local repository and add to the repository | 432 | --- Update manifest file for a local repository |
| 402 | -- information with regard to the given name and version. | 433 | -- adding information about a version of a package installed in that repository. |
| 403 | -- A file called 'manifest' will be written in the root of the given | ||
| 404 | -- repository directory. | ||
| 405 | -- @param name string: Name of a package from the repository. | 434 | -- @param name string: Name of a package from the repository. |
| 406 | -- @param version string: Version of a package from the repository. | 435 | -- @param version string: Version of a package from the repository. |
| 407 | -- @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, |
| @@ -409,14 +438,14 @@ end | |||
| 409 | -- @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, |
| 410 | -- "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, |
| 411 | -- "none" for using the default dependency mode from the configuration. | 440 | -- "none" for using the default dependency mode from the configuration. |
| 412 | -- @return boolean or (nil, string): True if manifest was generated, | 441 | -- @return boolean or (nil, string): True if manifest was updated successfully, |
| 413 | -- or nil and an error message. | 442 | -- or nil and an error message. |
| 414 | function manif.update_manifest(name, version, repo, deps_mode) | 443 | function manif.add_to_manifest(name, version, repo, deps_mode) |
| 415 | assert(type(name) == "string") | 444 | assert(type(name) == "string") |
| 416 | assert(type(version) == "string") | 445 | assert(type(version) == "string") |
| 417 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | 446 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
| 418 | assert(type(deps_mode) == "string") | 447 | assert(type(deps_mode) == "string") |
| 419 | 448 | ||
| 420 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 449 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
| 421 | 450 | ||
| 422 | local manifest, err = manif_core.load_local_manifest(rocks_dir) | 451 | local manifest, err = manif_core.load_local_manifest(rocks_dir) |
| @@ -437,6 +466,52 @@ function manif.update_manifest(name, version, repo, deps_mode) | |||
| 437 | return save_table(rocks_dir, "manifest", manifest) | 466 | return save_table(rocks_dir, "manifest", manifest) |
| 438 | end | 467 | end |
| 439 | 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) | ||
| 513 | end | ||
| 514 | |||
| 440 | function manif.zip_manifests() | 515 | function manif.zip_manifests() |
| 441 | for ver in util.lua_versions() do | 516 | for ver in util.lua_versions() do |
| 442 | local file = "manifest-"..ver | 517 | local file = "manifest-"..ver |
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 |
