Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Larpon/vmon
An asynchronous directory file change watcher module for Windows, macOS and Linux wrapped for V
https://github.com/Larpon/vmon
filewatcher v vlang vlang-module wrapper
Last synced: 2 months ago
JSON representation
An asynchronous directory file change watcher module for Windows, macOS and Linux wrapped for V
- Host: GitHub
- URL: https://github.com/Larpon/vmon
- Owner: larpon
- License: mit
- Created: 2021-03-25T13:03:02.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-21T09:20:01.000Z (5 months ago)
- Last Synced: 2024-08-21T10:45:48.708Z (5 months ago)
- Topics: filewatcher, v, vlang, vlang-module, wrapper
- Language: C
- Homepage:
- Size: 68.4 KB
- Stars: 34
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-v - vmon - Asynchronously watch for file changes in a directory. The module is essentially a V wrapper for `septag/dmon`. It works for Windows, macOS and Linux. (Libraries / File handling)
README
# vmon
A V module for asynchronously watching for file changes in a directory.
The module is essentially a wrapper for [septag/dmon](https://github.com/septag/dmon).
It works for Windows, macOS and Linux.Currently `vmon` offers a few additional features over the code in `dmon`.
* Automatic shared access to the user data in the callback thread (via `sync.Mutex`)
* Automatic init/free of memory resources on clean program exits# Install
```bash
v install https://github.com/larpon/vmon
```# Usage
For example usage see `examples/watch_and_wait`
```v
v run ~/.vmodules/vmon/examples/watch_and_wait
```To watch a directory asynchronously for *file* changes simply do:
```v
import os
import vmonfn watch_callback(watch_id vmon.WatchID, action vmon.Action, root_path string, file_path string, old_file_path string, user_data voidptr) {
// ... do stuff here
}fn main() {
vmon.watch(os.home_dir(), watch_callback, 0, voidptr(0)) or { panic(err) }
// ... do stuff here, wait or block the main thread, e.g.:
time.sleep(10 * time.second)
}
```Since the file watching is running in it's own thread remember to block your main thread while watching for changes, otherwise the app will exit immediately.
# Notes
Please note that [septag/dmon](https://github.com/septag/dmon) is [licensed](https://github.com/septag/dmon#license-bsd-2-clause) under BSD 2-clause
while the V wrapper code is licensed under MIT.Please also note that your user need correct file permission access
to the directories you're trying to watch. So watching a place
like `/tmp` on Unix isn't always possible since this is usually owned by root.
However, you're usually allowed to make subdirectories in `/tmp` which can be watched.Also please note that currently you won't receive events from changes to *directories* in the
watched path since this is not supported in the C project we rely on.