diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-17 15:56:13 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-18 11:24:07 -0300 |
commit | 94b25d8922a2bae1c6d5e36bf6b0cffd86d91f2a (patch) | |
tree | 6e7a9ffb87ab0766439ab68c036c6c4f4a7dc5c8 | |
parent | f20f4cca65d6433cb354b584ee25339f152e72ec (diff) | |
download | luarocks-94b25d8922a2bae1c6d5e36bf6b0cffd86d91f2a.tar.gz luarocks-94b25d8922a2bae1c6d5e36bf6b0cffd86d91f2a.tar.bz2 luarocks-94b25d8922a2bae1c6d5e36bf6b0cffd86d91f2a.zip |
fs: support both table and number in set_time
-rw-r--r-- | src/luarocks/fs/lua.lua | 9 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 15 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 9 |
3 files changed, 32 insertions, 1 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 58dcf5c1..f2fa50b6 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -572,8 +572,17 @@ function fs_lua.is_file(file) | |||
572 | return lfs.attributes(file, "mode") == "file" | 572 | return lfs.attributes(file, "mode") == "file" |
573 | end | 573 | end |
574 | 574 | ||
575 | -- Set access and modification times for a file. | ||
576 | -- @param filename File to set access and modification times for. | ||
577 | -- @param time may be a number containing the format returned | ||
578 | -- by os.time, or a table ready to be processed via os.time; if | ||
579 | -- nil, current time is assumed. | ||
575 | function fs_lua.set_time(file, time) | 580 | function fs_lua.set_time(file, time) |
581 | assert(time == nil or type(time) == "table" or type(time) == "number") | ||
576 | file = dir.normalize(file) | 582 | file = dir.normalize(file) |
583 | if type(time) == "table" then | ||
584 | time = os.time(time) | ||
585 | end | ||
577 | return lfs.touch(file, time) | 586 | return lfs.touch(file, time) |
578 | end | 587 | end |
579 | 588 | ||
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 6a91775f..de63eb81 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -248,9 +248,22 @@ function tools.browser(url) | |||
248 | return fs.execute(cfg.web_browser, url) | 248 | return fs.execute(cfg.web_browser, url) |
249 | end | 249 | end |
250 | 250 | ||
251 | -- Set access and modification times for a file. | ||
252 | -- @param filename File to set access and modification times for. | ||
253 | -- @param time may be a string or number containing the format returned | ||
254 | -- by os.time, or a table ready to be processed via os.time; if | ||
255 | -- nil, current time is assumed. | ||
251 | function tools.set_time(file, time) | 256 | function tools.set_time(file, time) |
257 | assert(time == nil or type(time) == "table" or type(time) == "number") | ||
252 | file = dir.normalize(file) | 258 | file = dir.normalize(file) |
253 | return fs.execute(vars.TOUCH, "-d", "@"..tostring(time), file) | 259 | local flag = "" |
260 | if type(time) == "number" then | ||
261 | time = os.date("*t", time) | ||
262 | end | ||
263 | if type(time) == "table" then | ||
264 | flag = ("-t %04d%02d%02d%02d%02d%02d"):format(time.year, time.month, time.day, time.hour, time.min, time.sec) | ||
265 | end | ||
266 | return fs.execute(vars.TOUCH .. " " .. flag, file) | ||
254 | end | 267 | end |
255 | 268 | ||
256 | --- Create a temporary directory. | 269 | --- Create a temporary directory. |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index de3d9031..0a27cbe3 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -310,4 +310,13 @@ function tools.browser(url) | |||
310 | return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url)) | 310 | return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url)) |
311 | end | 311 | end |
312 | 312 | ||
313 | -- Set access and modification times for a file. | ||
314 | -- @param filename File to set access and modification times for. | ||
315 | -- @param time may be a string or number containing the format returned | ||
316 | -- by os.time, or a table ready to be processed via os.time; if | ||
317 | -- nil, current time is assumed. | ||
318 | function tools.set_time(filename, time) | ||
319 | return true -- FIXME | ||
320 | end | ||
321 | |||
313 | return tools | 322 | return tools |