diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/bin/luarocks | 1 | ||||
| -rw-r--r-- | src/luarocks/purge.lua | 48 | ||||
| -rw-r--r-- | src/luarocks/repos.lua | 18 |
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") | |||
| 20 | commands.show = require("luarocks.show") | 20 | commands.show = require("luarocks.show") |
| 21 | commands.new_version = require("luarocks.new_version") | 21 | commands.new_version = require("luarocks.new_version") |
| 22 | commands.lint = require("luarocks.lint") | 22 | commands.lint = require("luarocks.lint") |
| 23 | commands.purge = require("luarocks.purge") | ||
| 23 | 24 | ||
| 24 | command_line.run_command(...) | 25 | command_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. | ||
| 4 | module("luarocks.purge", package.seeall) | ||
| 5 | |||
| 6 | local util = require("luarocks.util") | ||
| 7 | local fs = require("luarocks.fs") | ||
| 8 | local path = require("luarocks.path") | ||
| 9 | local search = require("luarocks.search") | ||
| 10 | local deps = require("luarocks.deps") | ||
| 11 | local repos = require("luarocks.repos") | ||
| 12 | local manif = require("luarocks.manif") | ||
| 13 | local cfg = require("luarocks.cfg") | ||
| 14 | |||
| 15 | help_summary = "Remove all installed rocks from a tree." | ||
| 16 | help_arguments = "--tree=<tree>" | ||
| 17 | help = [[ | ||
| 18 | This command removes all rocks from a given tree. | ||
| 19 | |||
| 20 | The --tree argument is mandatory: luarocks purge does not | ||
| 21 | assume a default tree. | ||
| 22 | ]] | ||
| 23 | |||
| 24 | function 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) | ||
| 48 | end | ||
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 |
| 262 | function 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. | ||
| 266 | function 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 |
