/src/luarocks/fetch/cvs.lua

http://github.com/keplerproject/luarocks · Lua · 55 lines · 39 code · 8 blank · 8 comment · 11 complexity · 981e5ef26ff4d1a1378ee9bfd30a5a67 MD5 · raw file

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