summaryrefslogtreecommitdiff
path: root/xmake/core/base/fwatcher.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-23 00:02:11 +0800
committerruki <[email protected]>2022-07-23 00:02:11 +0800
commit67a7d807940ff5ebdda3a5054265422f31fca6a8 (patch)
treef79e4ac5c5da0f255ce0bd70f7e84c6b6816275a /xmake/core/base/fwatcher.lua
parentb9327d0744edbf212120e77b345008954eac5851 (diff)
add some fwatcher api
Diffstat (limited to 'xmake/core/base/fwatcher.lua')
-rw-r--r--xmake/core/base/fwatcher.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/xmake/core/base/fwatcher.lua b/xmake/core/base/fwatcher.lua
index 3bd557a7f..b0c210216 100644
--- a/xmake/core/base/fwatcher.lua
+++ b/xmake/core/base/fwatcher.lua
@@ -220,4 +220,61 @@ function fwatcher.watchdirs(watchdirs, callback, opt)
return ok, errors
end
+-- watch the created file path in directories
+--
+-- @param watchdirs the watch directories, pattern path string or path list
+-- @param callback the event callback
+-- @param opt the option, e.g. {timeout = -1, recursion = true}
+--
+-- @code
+-- fwatcher.on_created("/tmp/test_*", function (filepath)
+-- print(filepath)
+-- end, {timeout = -1, recursion = true})
+-- @endcode
+function fwatcher.on_created(watchdirs, callback, opt)
+ return fwatcher.watchdirs(watchdirs, function (event)
+ if event and event.type == fwatcher.ET_CREATE then
+ callback(event.path)
+ end
+ end, opt)
+end
+
+-- watch the modified file path in directories
+--
+-- @param watchdirs the watch directories, pattern path string or path list
+-- @param callback the event callback
+-- @param opt the option, e.g. {timeout = -1, recursion = true}
+--
+-- @code
+-- fwatcher.on_modified("/tmp/test_*", function (filepath)
+-- print(filepath)
+-- end, {timeout = -1, recursion = true})
+-- @endcode
+function fwatcher.on_modified(watchdirs, callback, opt)
+ return fwatcher.watchdirs(watchdirs, function (event)
+ if event and event.type == fwatcher.ET_MODIFY then
+ callback(event.path)
+ end
+ end, opt)
+end
+
+-- watch the deleted file path in directories
+--
+-- @param watchdirs the watch directories, pattern path string or path list
+-- @param callback the event callback
+-- @param opt the option, e.g. {timeout = -1, recursion = true}
+--
+-- @code
+-- fwatcher.on_deleted("/tmp/test_*", function (filepath)
+-- print(filepath)
+-- end, {timeout = -1, recursion = true})
+-- @endcode
+function fwatcher.on_deleted(watchdirs, callback, opt)
+ return fwatcher.watchdirs(watchdirs, function (event)
+ if event and event.type == fwatcher.ET_DELETE then
+ callback(event.path)
+ end
+ end, opt)
+end
+
return fwatcher