aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2012-09-24 18:19:01 -0300
committerHisham Muhammad <hisham@gobolinux.org>2012-09-24 18:19:01 -0300
commitb20c561b8fcfcf4cecfd8fbb40ea7857193a4f8c (patch)
tree3ca7e40e9ce70778eefdfb31238003933ed9ec57
parent1afa78ff5f88d99e949d24027274ce6a8831c656 (diff)
downloadluarocks-b20c561b8fcfcf4cecfd8fbb40ea7857193a4f8c.tar.gz
luarocks-b20c561b8fcfcf4cecfd8fbb40ea7857193a4f8c.tar.bz2
luarocks-b20c561b8fcfcf4cecfd8fbb40ea7857193a4f8c.zip
Add 'purge' command. Closes #25.
-rwxr-xr-xsrc/bin/luarocks1
-rw-r--r--src/luarocks/purge.lua48
-rw-r--r--src/luarocks/repos.lua18
3 files changed, 61 insertions, 6 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks
index e94d895f..aaafb905 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -20,5 +20,6 @@ commands.path = require("luarocks.path")
20commands.show = require("luarocks.show") 20commands.show = require("luarocks.show")
21commands.new_version = require("luarocks.new_version") 21commands.new_version = require("luarocks.new_version")
22commands.lint = require("luarocks.lint") 22commands.lint = require("luarocks.lint")
23commands.purge = require("luarocks.purge")
23 24
24command_line.run_command(...) 25command_line.run_command(...)
diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua
new file mode 100644
index 00000000..dc6b822d
--- /dev/null
+++ b/src/luarocks/purge.lua
@@ -0,0 +1,48 @@
1
2--- Module implementing the LuaRocks "purge" command.
3-- Remove all rocks from a given tree.
4module("luarocks.purge", package.seeall)
5
6local util = require("luarocks.util")
7local fs = require("luarocks.fs")
8local path = require("luarocks.path")
9local search = require("luarocks.search")
10local deps = require("luarocks.deps")
11local repos = require("luarocks.repos")
12local manif = require("luarocks.manif")
13local cfg = require("luarocks.cfg")
14
15help_summary = "Remove all installed rocks from a tree."
16help_arguments = "--tree=<tree>"
17help = [[
18This command removes all rocks from a given tree.
19
20The --tree argument is mandatory: luarocks purge does not
21assume a default tree.
22]]
23
24function run(...)
25 local flags = util.parse_flags(...)
26
27 local tree = flags["tree"]
28
29 if type(tree) ~= "string" then
30 return nil, "The --tree argument is mandatory, see help."
31 end
32
33 local results = {}
34 local query = search.make_query("")
35 query.exact_name = false
36 search.manifest_search(results, path.rocks_dir(tree), query)
37
38 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
40 util.printout("Removing "..package.." "..version.."...")
41 local ok, err = repos.delete_version(package, version, true)
42 if not ok then
43 util.printerr(err)
44 end
45 end
46 end
47 return manif.make_manifest(cfg.rocks_dir)
48end
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua
index e6f0c5f7..30c61f55 100644
--- a/src/luarocks/repos.lua
+++ b/src/luarocks/repos.lua
@@ -259,7 +259,11 @@ end
259-- Version numbers are compared as exact string comparison. 259-- Version numbers are compared as exact string comparison.
260-- @param name string: name of package 260-- @param name string: name of package
261-- @param version string: package version in string format 261-- @param version string: package version in string format
262function delete_version(name, version) 262-- @param quick boolean: do not try to fix the versioned name
263-- of another version that provides the same module that
264-- was deleted. This is used during 'purge', as every module
265-- will be eventually deleted.
266function delete_version(name, version, quick)
263 assert(type(name) == "string") 267 assert(type(name) == "string")
264 assert(type(version) == "string") 268 assert(type(version) == "string")
265 269
@@ -274,11 +278,13 @@ function delete_version(name, version)
274 if not ok then return nil, "Failed deleting "..versioned end 278 if not ok then return nil, "Failed deleting "..versioned end
275 else 279 else
276 local ok = fs.delete(target) 280 local ok = fs.delete(target)
277 local next_name, next_version = manif.find_next_provider(target) 281 if not quick then
278 if next_name then 282 local next_name, next_version = manif.find_next_provider(target)
279 local versioned = path.versioned_name(target, deploy_dir, next_name, next_version) 283 if next_name then
280 fs.move(versioned, target) 284 local versioned = path.versioned_name(target, deploy_dir, next_name, next_version)
281 fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) 285 fs.move(versioned, target)
286 fs.remove_dir_tree_if_empty(dir.dir_name(versioned))
287 end
282 end 288 end
283 fs.remove_dir_tree_if_empty(dir.dir_name(target)) 289 fs.remove_dir_tree_if_empty(dir.dir_name(target))
284 if not ok then return nil, "Failed deleting "..target end 290 if not ok then return nil, "Failed deleting "..target end