From a1f62e69ee7fdb1dfd6dc36aad48e1306a70bb14 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 17 Nov 2013 19:45:24 -0200 Subject: Add --force flag. Should be useful for François Perrad's work on the BuildRoot infrastructure for LuaRocks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/luarocks/unpack.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua index 70c116fd..95762a2c 100644 --- a/src/luarocks/unpack.lua +++ b/src/luarocks/unpack.lua @@ -10,11 +10,13 @@ local build = require("luarocks.build") local dir = require("luarocks.dir") help_summary = "Unpack the contents of a rock." -help_arguments = "{| []}" +help_arguments = "[--force] {| []}" 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." end - - 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." end - 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(...) end if name:match(".*%.rock") or name:match(".*%.rockspec") then - return run_unpacker(name) + return run_unpacker(name, flags["force"]) else local search = require("luarocks.search") return search.act_on_src_or_rockspec(run_unpacker, name, version) -- cgit v1.2.3-55-g6feb