diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2013-07-17 18:25:23 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-07-17 18:25:23 -0300 |
commit | ce3f3cf9db6abcb6c8008ea9a1fd674bfa4d91a8 (patch) | |
tree | 8b81308c24ae5bbf4030a571c1f10accbeca4143 | |
parent | c0d6ec090bcfbdc3895809fd914b3724e2742782 (diff) | |
download | luarocks-ce3f3cf9db6abcb6c8008ea9a1fd674bfa4d91a8.tar.gz luarocks-ce3f3cf9db6abcb6c8008ea9a1fd674bfa4d91a8.tar.bz2 luarocks-ce3f3cf9db6abcb6c8008ea9a1fd674bfa4d91a8.zip |
Add --old-versions to 'purge'.
-rw-r--r-- | src/luarocks/purge.lua | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua index 6b094061..e76a82e9 100644 --- a/src/luarocks/purge.lua +++ b/src/luarocks/purge.lua | |||
@@ -11,14 +11,22 @@ local deps = require("luarocks.deps") | |||
11 | local repos = require("luarocks.repos") | 11 | local repos = require("luarocks.repos") |
12 | local manif = require("luarocks.manif") | 12 | local manif = require("luarocks.manif") |
13 | local cfg = require("luarocks.cfg") | 13 | local cfg = require("luarocks.cfg") |
14 | local remove = require("luarocks.remove") | ||
14 | 15 | ||
15 | help_summary = "Remove all installed rocks from a tree." | 16 | help_summary = "Remove all installed rocks from a tree." |
16 | help_arguments = "--tree=<tree>" | 17 | help_arguments = "--tree=<tree> [--old-versions]" |
17 | help = [[ | 18 | help = [[ |
18 | This command removes all rocks from a given tree. | 19 | This command removes rocks en masse from a given tree. |
20 | By default, it removes all rocks from a tree. | ||
19 | 21 | ||
20 | The --tree argument is mandatory: luarocks purge does not | 22 | The --tree argument is mandatory: luarocks purge does not |
21 | assume a default tree. | 23 | assume a default tree. |
24 | |||
25 | --old-versions Keep the highest-numbered version of each | ||
26 | rock and remove the other ones. By default | ||
27 | it only removes old versions if they are | ||
28 | not needed as dependencies. This can be | ||
29 | overridden with the flag --force. | ||
22 | ]] | 30 | ]] |
23 | 31 | ||
24 | function run(...) | 32 | function run(...) |
@@ -35,12 +43,26 @@ function run(...) | |||
35 | query.exact_name = false | 43 | query.exact_name = false |
36 | search.manifest_search(results, path.rocks_dir(tree), query) | 44 | search.manifest_search(results, path.rocks_dir(tree), query) |
37 | 45 | ||
46 | local sort = function(a,b) return deps.compare_versions(b,a) end | ||
47 | if flags["old-versions"] then | ||
48 | sort = deps.compare_versions | ||
49 | end | ||
50 | |||
38 | for package, versions in util.sortedpairs(results) do | 51 | for package, versions in util.sortedpairs(results) do |
39 | for version, repositories in util.sortedpairs(versions, function(a,b) return deps.compare_versions(b,a) end) do | 52 | for version, repositories in util.sortedpairs(versions, sort) do |
40 | util.printout("Removing "..package.." "..version.."...") | 53 | if flags["old-versions"] then |
41 | local ok, err = repos.delete_version(package, version, true) | 54 | util.printout("Keeping "..package.." "..version.."...") |
42 | if not ok then | 55 | local ok, err = remove.remove_other_versions(package, version, flags["force"]) |
43 | util.printerr(err) | 56 | if not ok then |
57 | util.printerr(err) | ||
58 | end | ||
59 | break | ||
60 | else | ||
61 | util.printout("Removing "..package.." "..version.."...") | ||
62 | local ok, err = repos.delete_version(package, version, true) | ||
63 | if not ok then | ||
64 | util.printerr(err) | ||
65 | end | ||
44 | end | 66 | end |
45 | end | 67 | end |
46 | end | 68 | end |