diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2013-11-17 19:45:24 -0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-11-17 19:45:24 -0200 |
| commit | a1f62e69ee7fdb1dfd6dc36aad48e1306a70bb14 (patch) | |
| tree | 8cce37ba70b166783b048a1064ab3c1a42f741ba /src | |
| parent | 64ca4ac45a4e5dad245f6f1c3dd93b097ec55c89 (diff) | |
| download | luarocks-a1f62e69ee7fdb1dfd6dc36aad48e1306a70bb14.tar.gz luarocks-a1f62e69ee7fdb1dfd6dc36aad48e1306a70bb14.tar.bz2 luarocks-a1f62e69ee7fdb1dfd6dc36aad48e1306a70bb14.zip | |
Add --force flag.
Should be useful for François Perrad's work on the BuildRoot infrastructure for LuaRocks.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/unpack.lua | 19 |
1 files changed, 12 insertions, 7 deletions
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") | |||
| 10 | local dir = require("luarocks.dir") | 10 | local dir = require("luarocks.dir") |
| 11 | 11 | ||
| 12 | help_summary = "Unpack the contents of a rock." | 12 | help_summary = "Unpack the contents of a rock." |
| 13 | help_arguments = "{<rock>|<name> [<version>]}" | 13 | help_arguments = "[--force] {<rock>|<name> [<version>]}" |
| 14 | help = [[ | 14 | help = [[ |
| 15 | Unpacks the contents of a rock in a newly created directory. | 15 | Unpacks the contents of a rock in a newly created directory. |
| 16 | Argument may be a rock file, or the name of a rock in a rocks server. | 16 | Argument may be a rock file, or the name of a rock in a rocks server. |
| 17 | In the latter case, the app version may be given as a second argument. | 17 | In the latter case, the app version may be given as a second argument. |
| 18 | |||
| 19 | --force Unpack files even if the output directory already exists. | ||
| 18 | ]] | 20 | ]] |
| 19 | 21 | ||
| 20 | --- Load a rockspec file to the given directory, fetches the source | 22 | --- Load a rockspec file to the given directory, fetches the source |
| @@ -88,7 +90,7 @@ end | |||
| 88 | -- @param file string: A rockspec or .rock URL. | 90 | -- @param file string: A rockspec or .rock URL. |
| 89 | -- @return boolean or (nil, string): true if successful or nil followed | 91 | -- @return boolean or (nil, string): true if successful or nil followed |
| 90 | -- by an error message. | 92 | -- by an error message. |
| 91 | local function run_unpacker(file) | 93 | local function run_unpacker(file, force) |
| 92 | assert(type(file) == "string") | 94 | assert(type(file) == "string") |
| 93 | 95 | ||
| 94 | local base_name = dir.base_name(file) | 96 | local base_name = dir.base_name(file) |
| @@ -100,12 +102,15 @@ local function run_unpacker(file) | |||
| 100 | if not extension then | 102 | if not extension then |
| 101 | return nil, file.." does not seem to be a valid filename." | 103 | return nil, file.." does not seem to be a valid filename." |
| 102 | end | 104 | end |
| 103 | 105 | ||
| 104 | if (fs.exists(dir_name)) then | 106 | local exists = fs.exists(dir_name) |
| 107 | if exists and not force then | ||
| 105 | return nil, "Directory "..dir_name.." already exists." | 108 | return nil, "Directory "..dir_name.." already exists." |
| 106 | end | 109 | end |
| 107 | local ok, err = fs.make_dir(dir_name) | 110 | if not exists then |
| 108 | if not ok then return nil, err end | 111 | local ok, err = fs.make_dir(dir_name) |
| 112 | if not ok then return nil, err end | ||
| 113 | end | ||
| 109 | local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name)) | 114 | local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name)) |
| 110 | 115 | ||
| 111 | local rockspec, err | 116 | local rockspec, err |
| @@ -149,7 +154,7 @@ function run(...) | |||
| 149 | end | 154 | end |
| 150 | 155 | ||
| 151 | if name:match(".*%.rock") or name:match(".*%.rockspec") then | 156 | if name:match(".*%.rock") or name:match(".*%.rockspec") then |
| 152 | return run_unpacker(name) | 157 | return run_unpacker(name, flags["force"]) |
| 153 | else | 158 | else |
| 154 | local search = require("luarocks.search") | 159 | local search = require("luarocks.search") |
| 155 | return search.act_on_src_or_rockspec(run_unpacker, name, version) | 160 | return search.act_on_src_or_rockspec(run_unpacker, name, version) |
