aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2019-03-28 23:39:21 -0300
committerHisham Muhammad <hisham@gobolinux.org>2019-04-01 16:26:30 -0300
commit8283b817efd6fadad62794045d6bebad71e063cd (patch)
tree274bddbf260903a68735dcc6ea360a44a214aa85
parentfbb3431367a145e73bd038b0c779fd8355c997b4 (diff)
downloadluarocks-8283b817efd6fadad62794045d6bebad71e063cd.tar.gz
luarocks-8283b817efd6fadad62794045d6bebad71e063cd.tar.bz2
luarocks-8283b817efd6fadad62794045d6bebad71e063cd.zip
init: ensure --reset resets lua wrapper and config file
-rw-r--r--src/luarocks/cmd/init.lua44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua
index 28c6f5d5..b1bb3b51 100644
--- a/src/luarocks/cmd/init.lua
+++ b/src/luarocks/cmd/init.lua
@@ -31,7 +31,7 @@ Options for specifying rockspec data:
31 link to. 31 link to.
32]] 32]]
33 33
34local function write_gitignore() 34local function write_gitignore(entries)
35 local gitignore = "" 35 local gitignore = ""
36 local fd = io.open(".gitignore", "r") 36 local fd = io.open(".gitignore", "r")
37 if fd then 37 if fd then
@@ -41,7 +41,8 @@ local function write_gitignore()
41 end 41 end
42 42
43 fd = io.open(".gitignore", gitignore and "a" or "w") 43 fd = io.open(".gitignore", gitignore and "a" or "w")
44 for _, entry in ipairs({"/lua", "/lua_modules"}) do 44 for _, entry in ipairs(entries) do
45 entry = "/" .. entry
45 if not gitignore:find("\n"..entry.."\n", 1, true) then 46 if not gitignore:find("\n"..entry.."\n", 1, true) then
46 fd:write(entry.."\n") 47 fd:write(entry.."\n")
47 end 48 end
@@ -82,11 +83,27 @@ function init.command(flags, name, version)
82 util.printout("Checking your Lua installation ...") 83 util.printout("Checking your Lua installation ...")
83 local ok, err = deps.check_lua(cfg.variables) 84 local ok, err = deps.check_lua(cfg.variables)
84 if not ok then 85 if not ok then
85 util.warning(err) 86 return nil, err
86 end 87 end
87 88
89 local ext = cfg.wrapper_suffix
90 local luarocks_wrapper = "luarocks" .. ext
91 local lua_wrapper = "lua" .. ext
92
93 if flags["reset"] then
94 fs.delete(lua_wrapper)
95 for v in util.lua_versions() do
96 local config_file = dir.path(".luarocks", "config-"..v..".lua")
97 if v ~= cfg.lua_version then
98 fs.move(config_file, config_file .. "~")
99 else
100 fs.delete(config_file)
101 end
102 end
103 end
104
88 util.printout("Adding entries to .gitignore ...") 105 util.printout("Adding entries to .gitignore ...")
89 write_gitignore() 106 write_gitignore({ luarocks_wrapper, lua_wrapper, "lua_modules" })
90 107
91 util.printout("Preparing ./.luarocks/ ...") 108 util.printout("Preparing ./.luarocks/ ...")
92 fs.make_dir(".luarocks") 109 fs.make_dir(".luarocks")
@@ -124,9 +141,7 @@ function init.command(flags, name, version)
124 fs.make_dir("lua_modules/lib/luarocks/rocks-" .. cfg.lua_version) 141 fs.make_dir("lua_modules/lib/luarocks/rocks-" .. cfg.lua_version)
125 local tree = dir.path(pwd, "lua_modules") 142 local tree = dir.path(pwd, "lua_modules")
126 143
127 local ext = cfg.wrapper_suffix 144 luarocks_wrapper = dir.path(".", luarocks_wrapper)
128
129 local luarocks_wrapper = "./luarocks" .. ext
130 if not fs.exists(luarocks_wrapper) then 145 if not fs.exists(luarocks_wrapper) then
131 util.printout("Preparing " .. luarocks_wrapper .. " ...") 146 util.printout("Preparing " .. luarocks_wrapper .. " ...")
132 fs.wrap_script(arg[0], "luarocks", "none", nil, nil, "--project-tree", tree) 147 fs.wrap_script(arg[0], "luarocks", "none", nil, nil, "--project-tree", tree)
@@ -134,18 +149,7 @@ function init.command(flags, name, version)
134 util.printout(luarocks_wrapper .. " already exists. Not overwriting it!") 149 util.printout(luarocks_wrapper .. " already exists. Not overwriting it!")
135 end 150 end
136 151
137 local lua_wrapper = "./lua" .. ext 152 lua_wrapper = dir.path(".", lua_wrapper)
138
139 if flags["reset"] then
140 fs.delete(lua_wrapper)
141 for v in util.lua_versions() do
142 if v ~= cfg.lua_version then
143 local config_file = dir.path(".luarocks", "config-"..v..".lua")
144 fs.move(config_file, config_file .. "~")
145 end
146 end
147 end
148
149 if not fs.exists(lua_wrapper) then 153 if not fs.exists(lua_wrapper) then
150 util.printout("Preparing " .. lua_wrapper .. " for version " .. cfg.lua_version .. "...") 154 util.printout("Preparing " .. lua_wrapper .. " for version " .. cfg.lua_version .. "...")
151 path.use_tree(tree) 155 path.use_tree(tree)