diff options
| author | ruki <[email protected]> | 2022-07-31 23:32:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-07-31 23:32:36 +0800 |
| commit | bb28bbb01c73ab1d7e455479f3338466a983d7d4 (patch) | |
| tree | c77b6942e68f972e01ef835ab794c42f4962c27e /xmake/core/base/os.lua | |
| parent | 1f27cde3a9c4b7e6866d677a2dd4e8a9cd6027e6 (diff) | |
add os.touch
Diffstat (limited to 'xmake/core/base/os.lua')
| -rw-r--r-- | xmake/core/base/os.lua | 13 |
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) |
