aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2013-07-17 18:25:23 -0300
committerHisham Muhammad <hisham@gobolinux.org>2013-07-17 18:25:23 -0300
commitce3f3cf9db6abcb6c8008ea9a1fd674bfa4d91a8 (patch)
tree8b81308c24ae5bbf4030a571c1f10accbeca4143
parentc0d6ec090bcfbdc3895809fd914b3724e2742782 (diff)
downloadluarocks-ce3f3cf9db6abcb6c8008ea9a1fd674bfa4d91a8.tar.gz
luarocks-ce3f3cf9db6abcb6c8008ea9a1fd674bfa4d91a8.tar.bz2
luarocks-ce3f3cf9db6abcb6c8008ea9a1fd674bfa4d91a8.zip
Add --old-versions to 'purge'.
-rw-r--r--src/luarocks/purge.lua36
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")
11local repos = require("luarocks.repos") 11local repos = require("luarocks.repos")
12local manif = require("luarocks.manif") 12local manif = require("luarocks.manif")
13local cfg = require("luarocks.cfg") 13local cfg = require("luarocks.cfg")
14local remove = require("luarocks.remove")
14 15
15help_summary = "Remove all installed rocks from a tree." 16help_summary = "Remove all installed rocks from a tree."
16help_arguments = "--tree=<tree>" 17help_arguments = "--tree=<tree> [--old-versions]"
17help = [[ 18help = [[
18This command removes all rocks from a given tree. 19This command removes rocks en masse from a given tree.
20By default, it removes all rocks from a tree.
19 21
20The --tree argument is mandatory: luarocks purge does not 22The --tree argument is mandatory: luarocks purge does not
21assume a default tree. 23assume 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
24function run(...) 32function 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