From 94b25d8922a2bae1c6d5e36bf6b0cffd86d91f2a Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 17 Jul 2018 15:56:13 -0300 Subject: fs: support both table and number in set_time --- src/luarocks/fs/lua.lua | 9 +++++++++ src/luarocks/fs/unix/tools.lua | 15 ++++++++++++++- src/luarocks/fs/win32/tools.lua | 9 +++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) (limited to 'src') 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) return lfs.attributes(file, "mode") == "file" end +-- Set access and modification times for a file. +-- @param filename File to set access and modification times for. +-- @param time may be a number containing the format returned +-- by os.time, or a table ready to be processed via os.time; if +-- nil, current time is assumed. function fs_lua.set_time(file, time) + assert(time == nil or type(time) == "table" or type(time) == "number") file = dir.normalize(file) + if type(time) == "table" then + time = os.time(time) + end return lfs.touch(file, time) end 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) return fs.execute(cfg.web_browser, url) end +-- Set access and modification times for a file. +-- @param filename File to set access and modification times for. +-- @param time may be a string or number containing the format returned +-- by os.time, or a table ready to be processed via os.time; if +-- nil, current time is assumed. function tools.set_time(file, time) + assert(time == nil or type(time) == "table" or type(time) == "number") file = dir.normalize(file) - return fs.execute(vars.TOUCH, "-d", "@"..tostring(time), file) + local flag = "" + if type(time) == "number" then + time = os.date("*t", time) + end + if type(time) == "table" then + flag = ("-t %04d%02d%02d%02d%02d%02d"):format(time.year, time.month, time.day, time.hour, time.min, time.sec) + end + return fs.execute(vars.TOUCH .. " " .. flag, file) end --- 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) return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url)) end +-- Set access and modification times for a file. +-- @param filename File to set access and modification times for. +-- @param time may be a string or number containing the format returned +-- by os.time, or a table ready to be processed via os.time; if +-- nil, current time is assumed. +function tools.set_time(filename, time) + return true -- FIXME +end + return tools -- cgit v1.2.3-55-g6feb