aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-09-25 19:04:36 -0400
committerHisham Muhammad <hisham@gobolinux.org>2018-09-26 08:55:09 -0400
commitc3360b669fcf2917ce89176ed8d62fc5d6e330e6 (patch)
treefd678e37bb4744f3bf5746ad127882ebd100d799
parentfa465f2bfd3641bbffccc70b2ded331ee6ab1766 (diff)
downloadluarocks-c3360b669fcf2917ce89176ed8d62fc5d6e330e6.tar.gz
luarocks-c3360b669fcf2917ce89176ed8d62fc5d6e330e6.tar.bz2
luarocks-c3360b669fcf2917ce89176ed8d62fc5d6e330e6.zip
Improve error messages when external tools are not found
Give informative error messages when external tools are not installed. In particular, give a nicer error on `luarocks pack` when 'zip' is not installed.
-rw-r--r--src/luarocks/cmd/unpack.lua2
-rw-r--r--src/luarocks/fs/lua.lua2
-rw-r--r--src/luarocks/fs/tools.lua13
-rw-r--r--src/luarocks/fs/unix/tools.lua8
-rw-r--r--src/luarocks/pack.lua5
5 files changed, 23 insertions, 7 deletions
diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua
index 83dec7fe..7d3b7ca4 100644
--- a/src/luarocks/cmd/unpack.lua
+++ b/src/luarocks/cmd/unpack.lua
@@ -61,7 +61,7 @@ local function unpack_rock(rock_file, dir_name, kind)
61 61
62 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name) 62 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name)
63 if not ok then 63 if not ok then
64 return nil, "Failed unzipping rock "..rock_file, errcode 64 return nil, err, errcode
65 end 65 end
66 ok, err = fs.change_dir(dir_name) 66 ok, err = fs.change_dir(dir_name)
67 if not ok then return nil, err end 67 if not ok then return nil, err end
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 13b46e19..43a636fb 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -111,7 +111,7 @@ function fs_lua.is_tool_available(tool_cmd, tool_name, arg)
111 arg = arg or "--version" 111 arg = arg or "--version"
112 assert(type(arg) == "string") 112 assert(type(arg) == "string")
113 113
114 if not fs.execute_quiet(fs.Q(tool_cmd), arg) then 114 if not fs.execute_quiet(tool_cmd, arg) then
115 local msg = "'%s' program not found. Make sure %s is installed and is available in your PATH " .. 115 local msg = "'%s' program not found. Make sure %s is installed and is available in your PATH " ..
116 "(or you may want to edit the 'variables.%s' value in file '%s')" 116 "(or you may want to edit the 'variables.%s' value in file '%s')"
117 return nil, msg:format(tool_cmd, tool_name, tool_name:upper(), cfg.which_config().nearest) 117 return nil, msg:format(tool_cmd, tool_name, tool_name:upper(), cfg.which_config().nearest)
diff --git a/src/luarocks/fs/tools.lua b/src/luarocks/fs/tools.lua
index d2dc08ae..691d670e 100644
--- a/src/luarocks/fs/tools.lua
+++ b/src/luarocks/fs/tools.lua
@@ -168,12 +168,14 @@ function tools.use_downloader(url, filename, cache)
168 curl_cmd = curl_cmd .. "--connect-timeout "..tostring(cfg.connection_timeout).." " 168 curl_cmd = curl_cmd .. "--connect-timeout "..tostring(cfg.connection_timeout).." "
169 end 169 end
170 ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." > "..fs.Q(filename))) 170 ok = fs.execute_string(fs.quiet_stderr(curl_cmd..fs.Q(url).." > "..fs.Q(filename)))
171 else
172 return false, "No downloader tool available -- please install 'wget' or 'curl' in your system"
171 end 173 end
172 if ok then 174 if ok then
173 return true, filename 175 return true, filename
174 else 176 else
175 os.remove(filename) 177 os.remove(filename)
176 return false 178 return false, "Failed downloading " .. url
177 end 179 end
178end 180end
179 181
@@ -189,9 +191,14 @@ function tools.get_md5(file)
189 if computed then 191 if computed then
190 computed = computed:match("("..("%x"):rep(32)..")") 192 computed = computed:match("("..("%x"):rep(32)..")")
191 end 193 end
192 if computed then return computed end 194 if computed then
195 return computed
196 else
197 return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file))
198 end
199 else
200 return false, "No MD5 checking tool available -- please install 'md5', 'md5sum' or 'openssl' in your system"
193 end 201 end
194 return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file))
195end 202end
196 203
197return tools 204return tools
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index f99582bd..c5d83018 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -125,6 +125,10 @@ end
125-- additional arguments. 125-- additional arguments.
126-- @return boolean: true on success, nil and error message on failure. 126-- @return boolean: true on success, nil and error message on failure.
127function tools.zip(zipfile, ...) 127function tools.zip(zipfile, ...)
128 local ok, err = fs.is_tool_available(vars.ZIP, "zip")
129 if not ok then
130 return nil, err
131 end
128 if fs.execute_quiet(vars.ZIP.." -r", zipfile, ...) then 132 if fs.execute_quiet(vars.ZIP.." -r", zipfile, ...) then
129 return true 133 return true
130 else 134 else
@@ -137,6 +141,10 @@ end
137-- @return boolean: true on success, nil and error message on failure. 141-- @return boolean: true on success, nil and error message on failure.
138function tools.unzip(zipfile) 142function tools.unzip(zipfile)
139 assert(zipfile) 143 assert(zipfile)
144 local ok, err = fs.is_tool_available(vars.UNZIP, "unzip", "-h")
145 if not ok then
146 return nil, err
147 end
140 if fs.execute_quiet(vars.UNZIP, zipfile) then 148 if fs.execute_quiet(vars.UNZIP, zipfile) then
141 return true 149 return true
142 else 150 else
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index cec370db..0c71aa76 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -43,8 +43,9 @@ function pack.pack_source_rock(rockspec_file)
43 43
44 fs.delete(rock_file) 44 fs.delete(rock_file)
45 fs.copy(rockspec_file, source_dir, "read") 45 fs.copy(rockspec_file, source_dir, "read")
46 if not fs.zip(rock_file, dir.base_name(rockspec_file), dir.base_name(source_file)) then 46 ok, err = fs.zip(rock_file, dir.base_name(rockspec_file), dir.base_name(source_file))
47 return nil, "Failed packing "..rock_file 47 if not ok then
48 return nil, "Failed packing "..rock_file.." - "..err
48 end 49 end
49 fs.pop_dir() 50 fs.pop_dir()
50 51