aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2011-08-26 19:35:08 -0300
committerHisham Muhammad <hisham@gobolinux.org>2011-08-26 19:35:28 -0300
commit14f42909edf4fd79a058484fc47013a3a22f6ab4 (patch)
treea792c27763506b1e958ae0e4a595fcae888e7d32
parentaaa176f595dafa36672b289dc451701d8904e7e7 (diff)
downloadluarocks-14f42909edf4fd79a058484fc47013a3a22f6ab4.tar.gz
luarocks-14f42909edf4fd79a058484fc47013a3a22f6ab4.tar.bz2
luarocks-14f42909edf4fd79a058484fc47013a3a22f6ab4.zip
simplify two functions into one.
-rw-r--r--src/luarocks/install.lua2
-rw-r--r--src/luarocks/path.lua26
-rw-r--r--src/luarocks/search.lua5
3 files changed, 13 insertions, 20 deletions
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index d7d87192..e99b4ce0 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -28,7 +28,7 @@ or a filename of a locally available rock.
28function install_binary_rock(rock_file) 28function install_binary_rock(rock_file)
29 assert(type(rock_file) == "string") 29 assert(type(rock_file) == "string")
30 30
31 local name, version, arch = path.parse_rock_name(rock_file) 31 local name, version, arch = path.parse_name(rock_file)
32 if not name then 32 if not name then
33 return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'." 33 return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'."
34 end 34 end
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index fe241aa5..219164ea 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -193,22 +193,18 @@ function bin_dir(name, version, repo)
193 return dir.path(rocks_dir(repo), name, version, "bin") 193 return dir.path(rocks_dir(repo), name, version, "bin")
194end 194end
195 195
196--- Extract name, version and arch of a rock filename. 196--- Extract name, version and arch of a rock filename,
197-- @param rock_file string: pathname of a rock 197-- or name, version and "rockspec" from a rockspec name.
198-- @param file_name string: pathname of a rock or rockspec
198-- @return (string, string, string) or nil: name, version and arch 199-- @return (string, string, string) or nil: name, version and arch
199-- of rock, or nil if name could not be parsed 200-- or nil if name could not be parsed
200function parse_rock_name(rock_file) 201function parse_name(file_name)
201 assert(type(rock_file) == "string") 202 assert(type(file_name) == "string")
202 return dir.base_name(rock_file):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") 203 if file_name:match("%.rock$") then
203end 204 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$")
204 205 else
205--- Extract name and version of a rockspec filename. 206 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.(rockspec)")
206-- @param rockspec_file string: pathname of a rockspec 207 end
207-- @return (string, string) or nil: name and version
208-- of rockspec, or nil if name could not be parsed
209function parse_rockspec_name(rockspec_file)
210 assert(type(rockspec_file) == "string")
211 return dir.base_name(rockspec_file):match("(.*)-([^-]+-%d+)%.(rockspec)")
212end 208end
213 209
214--- Make a rockspec or rock URL. 210--- Make a rockspec or rock URL.
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 493c2f45..127bba19 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -138,10 +138,7 @@ function disk_search(repo, query, results)
138 138
139 for _, name in pairs(fs.list_dir(repo)) do 139 for _, name in pairs(fs.list_dir(repo)) do
140 local pathname = dir.path(repo, name) 140 local pathname = dir.path(repo, name)
141 local rname, rversion, rarch = path.parse_rock_name(name) 141 local rname, rversion, rarch = path.parse_name(name)
142 if not rname then
143 rname, rversion, rarch = path.parse_rockspec_name(name)
144 end
145 if fs.is_dir(pathname) then 142 if fs.is_dir(pathname) then
146 for _, version in pairs(fs.list_dir(pathname)) do 143 for _, version in pairs(fs.list_dir(pathname)) do
147 if version:match("-%d+$") then 144 if version:match("-%d+$") then