Browse files

Add --force flag.

Should be useful for François Perrad's work on the BuildRoot infrastructure for LuaRocks.
  • Loading branch information...
1 parent 64ca4ac commit a1f62e69ee7fdb1dfd6dc36aad48e1306a70bb14 @hishamhm hishamhm committed Nov 17, 2013
Showing with 12 additions and 7 deletions.
  1. +12 −7 src/luarocks/unpack.lua
19 src/luarocks/unpack.lua
@@ -10,11 +10,13 @@ local build = require("")
local dir = require("luarocks.dir")
help_summary = "Unpack the contents of a rock."
-help_arguments = "{<rock>|<name> [<version>]}"
+help_arguments = "[--force] {<rock>|<name> [<version>]}"
help = [[
Unpacks the contents of a rock in a newly created directory.
Argument may be a rock file, or the name of a rock in a rocks server.
In the latter case, the app version may be given as a second argument.
+--force Unpack files even if the output directory already exists.
--- Load a rockspec file to the given directory, fetches the source
@@ -88,7 +90,7 @@ end
-- @param file string: A rockspec or .rock URL.
-- @return boolean or (nil, string): true if successful or nil followed
-- by an error message.
-local function run_unpacker(file)
+local function run_unpacker(file, force)
assert(type(file) == "string")
local base_name = dir.base_name(file)
@@ -100,12 +102,15 @@ local function run_unpacker(file)
if not extension then
return nil, file.." does not seem to be a valid filename."
- if (fs.exists(dir_name)) then
+ local exists = fs.exists(dir_name)
+ if exists and not force then
return nil, "Directory "..dir_name.." already exists."
- local ok, err = fs.make_dir(dir_name)
- if not ok then return nil, err end
+ if not exists then
+ local ok, err = fs.make_dir(dir_name)
+ if not ok then return nil, err end
+ end
local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name))
local rockspec, err
@@ -149,7 +154,7 @@ function run(...)
if name:match(".*%.rock") or name:match(".*%.rockspec") then
- return run_unpacker(name)
+ return run_unpacker(name, flags["force"])
local search = require("")
return search.act_on_src_or_rockspec(run_unpacker, name, version)

0 comments on commit a1f62e6

Please sign in to comment.