PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/luarocks/fetch/cvs.lua

http://github.com/keplerproject/luarocks
Lua | 55 lines | 39 code | 8 blank | 8 comment | 8 complexity | 981e5ef26ff4d1a1378ee9bfd30a5a67 MD5 | raw file
 1
 2--- Fetch back-end for retrieving sources from CVS.
 3local cvs = {}
 4
 5local unpack = unpack or table.unpack
 6
 7local fs = require("luarocks.fs")
 8local dir = require("luarocks.dir")
 9local util = require("luarocks.util")
10
11--- Download sources for building a rock, using CVS.
12-- @param rockspec table: The rockspec table
13-- @param extract boolean: Unused in this module (required for API purposes.)
14-- @param dest_dir string or nil: If set, will extract to the given directory.
15-- @return (string, string) or (nil, string): The absolute pathname of
16-- the fetched source tarball and the temporary directory created to
17-- store it; or nil and an error message.
18function cvs.get_sources(rockspec, extract, dest_dir)
19   assert(rockspec:type() == "rockspec")
20   assert(type(dest_dir) == "string" or not dest_dir)
21
22   local cvs_cmd = rockspec.variables.CVS
23   local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS")
24   if not ok then
25      return nil, err_msg
26   end
27
28   local name_version = rockspec.name .. "-" .. rockspec.version
29   local module = rockspec.source.module or dir.base_name(rockspec.source.url)
30   local command = {cvs_cmd, "-d"..rockspec.source.pathname, "export", module}
31   if rockspec.source.tag then
32      table.insert(command, 4, "-r")
33      table.insert(command, 5, rockspec.source.tag)
34   end
35   local store_dir
36   if not dest_dir then
37      store_dir = fs.make_temp_dir(name_version)
38      if not store_dir then
39         return nil, "Failed creating temporary directory."
40      end
41      util.schedule_function(fs.delete, store_dir)
42   else
43      store_dir = dest_dir
44   end
45   local ok, err = fs.change_dir(store_dir)
46   if not ok then return nil, err end
47   if not fs.execute(unpack(command)) then
48      return nil, "Failed fetching files from CVS."
49   end
50   fs.pop_dir()
51   return module, store_dir
52end
53
54
55return cvs