summaryrefslogtreecommitdiff
path: root/xmake/core/base/os.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-31 23:32:36 +0800
committerruki <[email protected]>2022-07-31 23:32:36 +0800
commitbb28bbb01c73ab1d7e455479f3338466a983d7d4 (patch)
treec77b6942e68f972e01ef835ab794c42f4962c27e /xmake/core/base/os.lua
parent1f27cde3a9c4b7e6866d677a2dd4e8a9cd6027e6 (diff)
add os.touch
Diffstat (limited to 'xmake/core/base/os.lua')
-rw-r--r--xmake/core/base/os.lua13
1 files changed, 11 insertions, 2 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 7dd0f3aad..fff5c8408 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -37,6 +37,7 @@ os._getpid = os._getpid or os.getpid
os._exit = os._exit or os.exit
os._mkdir = os._mkdir or os.mkdir
os._rmdir = os._rmdir or os.rmdir
+os._touch = os._touch or os.touch
os._tmpdir = os._tmpdir or os.tmpdir
os._setenv = os._setenv or os.setenv
os._getenvs = os._getenvs or os.getenvs
@@ -551,11 +552,19 @@ function os.cd(dir)
if os._SCHED_CHDIR then
os._SCHED_CHDIR(os.curdir())
end
-
- -- ok
return oldir
end
+-- touch file or directory, it will modify atime/mtime or create a new file
+-- we will do not change it if atime/mtime is zero
+function os.touch(filepath, opt)
+ opt = opt or {}
+ if not os._touch(filepath, opt.atime or 0, opt.mtime or 0) then
+ return false, string.format("cannot touch %s, %s", filepath, os.strerror())
+ end
+ return true
+end
+
-- create directories
function os.mkdir(dir)