Skip to content

Commit b704076

Browse files
committed
remove recursive as argument for cross-platform consistency
1 parent 456236f commit b704076

File tree

8 files changed

+22
-26
lines changed

8 files changed

+22
-26
lines changed

R/watch.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
#' triggers multiple event flag types, the callback will be called only once.
99
#' Default latency is 1s.
1010
#'
11-
#' @param path Character path to a file or directory to watch. Defaults to the
12-
#' current working directory.
13-
#' @param recursive Logical value, default TRUE, whether to recursively scan
14-
#' `path`, including all subdirectories.
11+
#' @param path Character path to a file, or directory to watch recursively.
12+
#' Defaults to the current working directory.
1513
#' @param callback A function or formula (see [rlang::as_function]) - to be
1614
#' called each time an event is triggered. The default, `NULL`, causes event
1715
#' flag types and paths to be written to `stdout` instead.
@@ -29,8 +27,8 @@
2927
#'
3028
#' @export
3129
#'
32-
watcher <- function(path = getwd(), recursive = TRUE, callback = NULL) {
33-
Watcher$new(path, recursive, callback)
30+
watcher <- function(path = getwd(), callback = NULL) {
31+
Watcher$new(path, callback)
3432
}
3533

3634
# Note: R6 class uses a field for 'running' instead of using 'fsw_is_running()'
@@ -41,14 +39,13 @@ Watcher <- R6Class(
4139
public = list(
4240
path = NULL,
4341
running = FALSE,
44-
initialize = function(path, recursive, callback) {
42+
initialize = function(path, callback) {
4543
if (is.null(self$path)) {
4644
self$path <- path.expand(path)
47-
recursive <- as.logical(recursive)
4845
if (!is.null(callback) && !is.function(callback)) {
4946
callback <- rlang::as_function(callback)
5047
}
51-
private$watch <- .Call(watcher_create, self$path, recursive, callback)
48+
private$watch <- .Call(watcher_create, self$path, callback)
5249
lockBinding("path", self)
5350
}
5451
invisible(self)

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ library(watcher)
5353
dir <- file.path(tempdir(), "watcher-example")
5454
dir.create(dir)
5555
56-
w <- watcher(dir, recursive = TRUE, callback = ~print("event triggered"))
56+
w <- watcher(dir, callback = ~print("event triggered"))
5757
w
5858
w$start()
5959

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ library(watcher)
4949
dir <- file.path(tempdir(), "watcher-example")
5050
dir.create(dir)
5151

52-
w <- watcher(dir, recursive = TRUE, callback = ~print("event triggered"))
52+
w <- watcher(dir, callback = ~print("event triggered"))
5353
w
5454
#> <Watcher>
5555
#> Public:
56-
#> initialize: function (path, recursive, callback)
57-
#> path: /tmp/RtmpvhoSAP/watcher-example
56+
#> initialize: function (path, callback)
57+
#> path: /tmp/Rtmp1YkKqF/watcher-example
5858
#> running: FALSE
5959
#> start: function ()
6060
#> stop: function ()

man/watcher.Rd

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
void (*eln2)(void (*)(void *), void *, double, int);
44

55
static const R_CallMethodDef callMethods[] = {
6-
{"watcher_create", (DL_FUNC) &watcher_create, 3},
6+
{"watcher_create", (DL_FUNC) &watcher_create, 2},
77
{"watcher_start_monitor", (DL_FUNC) &watcher_start_monitor, 1},
88
{"watcher_stop_monitor", (DL_FUNC) &watcher_stop_monitor, 1},
99
{NULL, NULL, 0}

src/watcher.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ static void session_finalizer(SEXP xptr) {
7777

7878
}
7979

80-
SEXP watcher_create(SEXP path, SEXP recursive, SEXP callback) {
80+
/* Note: recursive is always set for consistency of behaviour, as Windows and
81+
MacOS default monitors are always recursive this would apply only on Linux */
82+
83+
SEXP watcher_create(SEXP path, SEXP callback) {
8184

8285
const char *watch_path = CHAR(STRING_ELT(path, 0));
83-
const int recurse = LOGICAL(recursive)[0] == 1;
8486

8587
FSW_HANDLE handle = fsw_init_session(system_default_monitor_type);
8688
if (handle == NULL)
@@ -89,7 +91,7 @@ SEXP watcher_create(SEXP path, SEXP recursive, SEXP callback) {
8991
if (fsw_add_path(handle, watch_path) != FSW_OK)
9092
watcher_error(handle, "Failed to add path to watch");
9193

92-
if (fsw_set_recursive(handle, recurse) != FSW_OK)
94+
if (fsw_set_recursive(handle, true) != FSW_OK)
9395
watcher_error(handle, "Failed to set recursive watch");
9496

9597
if (fsw_set_callback(handle, process_events, callback) != FSW_OK)

src/watcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
extern void (*eln2)(void (*)(void *), void *, double, int);
2323

24-
SEXP watcher_create(SEXP, SEXP, SEXP);
24+
SEXP watcher_create(SEXP, SEXP);
2525
SEXP watcher_start_monitor(SEXP);
2626
SEXP watcher_stop_monitor(SEXP);
2727

tests/testthat/test-watch.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dir.create(dir)
44
dir.create(subdir)
55

66
test_that("watcher() logs", {
7-
w <- watcher(dir, recursive = FALSE, callback = NULL)
7+
w <- watcher(dir, callback = NULL)
88
expect_s3_class(w, "Watcher")
99
expect_false(w$running)
1010
expect_false(w$stop())
@@ -24,7 +24,7 @@ test_that("watcher() logs", {
2424

2525
test_that("watcher() callbacks", {
2626
x <- 0L
27-
w <- watcher(dir, recursive = TRUE, callback = ~ {x <<- x + 1L})
27+
w <- watcher(dir, callback = ~ {x <<- x + 1L})
2828
expect_output(print(w))
2929
expect_s3_class(w, "Watcher")
3030
expect_false(w$running)

0 commit comments

Comments
 (0)