diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-03 13:57:46 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-09 16:49:20 -0300 |
commit | 29513caaca2bfdf197e3bbdc27c24f0081639fbd (patch) | |
tree | 5a02c07562b417911866f1c9ec9ef4e703e8fe49 /src | |
parent | dc2ecc0488af83066c41eac92e6a8cc80fb47497 (diff) | |
download | luarocks-29513caaca2bfdf197e3bbdc27c24f0081639fbd.tar.gz luarocks-29513caaca2bfdf197e3bbdc27c24f0081639fbd.tar.bz2 luarocks-29513caaca2bfdf197e3bbdc27c24f0081639fbd.zip |
persist: save_default_lua_version
refactor into a separate function
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cmd/config.lua | 9 | ||||
-rw-r--r-- | src/luarocks/persist.lua | 18 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index 5c7cc6c9..e9b2fef4 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua | |||
@@ -278,17 +278,10 @@ function config_cmd.command(flags, var, val) | |||
278 | end | 278 | end |
279 | 279 | ||
280 | local prefix = dir.dir_name(cfg.config_files[scope].file) | 280 | local prefix = dir.dir_name(cfg.config_files[scope].file) |
281 | local ok, err = fs.make_dir(prefix) | 281 | local ok, err = persist.save_default_lua_version(prefix, val) |
282 | if not ok then | 282 | if not ok then |
283 | return nil, "could not set default Lua version: " .. err | 283 | return nil, "could not set default Lua version: " .. err |
284 | end | 284 | end |
285 | local fd, err = io.open(dir.path(prefix, "default-lua-version.lua"), "w") | ||
286 | if not fd then | ||
287 | return nil, "could not set default Lua version: " .. err | ||
288 | end | ||
289 | |||
290 | fd:write('return "' .. val .. '"\n') | ||
291 | fd:close() | ||
292 | print("Lua version will default to " .. val .. " in " .. prefix) | 285 | print("Lua version will default to " .. val .. " in " .. prefix) |
293 | end | 286 | end |
294 | 287 | ||
diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index b8060ea0..1c4b82b5 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua | |||
@@ -1,12 +1,12 @@ | |||
1 | 1 | ||
2 | --- Utility module for loading files into tables and | 2 | --- Utility module for loading files into tables and |
3 | -- saving tables into files. | 3 | -- saving tables into files. |
4 | -- Implemented separately to avoid interdependencies, | ||
5 | -- as it is used in the bootstrapping stage of the cfg module. | ||
6 | local persist = {} | 4 | local persist = {} |
7 | 5 | ||
8 | local core = require("luarocks.core.persist") | 6 | local core = require("luarocks.core.persist") |
9 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
8 | local dir = require("luarocks.dir") | ||
9 | local fs = require("luarocks.fs") | ||
10 | 10 | ||
11 | persist.load_into_table = core.load_into_table | 11 | persist.load_into_table = core.load_into_table |
12 | 12 | ||
@@ -239,4 +239,18 @@ function persist.load_config_file_if_basic(filename, cfg) | |||
239 | return tbl | 239 | return tbl |
240 | end | 240 | end |
241 | 241 | ||
242 | function persist.save_default_lua_version(prefix, lua_version) | ||
243 | local ok, err = fs.make_dir(prefix) | ||
244 | if not ok then | ||
245 | return nil, err | ||
246 | end | ||
247 | local fd, err = io.open(dir.path(prefix, "default-lua-version.lua"), "w") | ||
248 | if not fd then | ||
249 | return nil, err | ||
250 | end | ||
251 | fd:write('return "' .. lua_version .. '"\n') | ||
252 | fd:close() | ||
253 | return true | ||
254 | end | ||
255 | |||
242 | return persist | 256 | return persist |