Skip to content

Commit e852178

Browse files
committed
Support 'within=' in listRegisteredDirectories to replace 'prefix='.
This matches the updates to the /registered endpoint in the backend.
1 parent 6d32aa0 commit e852178

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

R/listRegisteredDirectories.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
#' If \code{TRUE}, this is set to the current user.
99
#' @param contains String containing an absolute path.
1010
#' If not \code{NULL}, results are filtered to directories that contain this path.
11+
#' @param within String containing an absolute path.
12+
#' If not \code{NULL}, results are filtered to directories that are equal to or lie within this path.
1113
#' @param prefix String containing an absolute path or a prefix thereof.
1214
#' If not \code{NULL}, results are filtered to directories that start with this string.
15+
#' This is soft-deprecated and users should prefer to use \code{within}.
1316
#' @param exists Logical scalar indicating whether to only report directories that exist on the filesystem.
1417
#' If \code{FALSE}, only non-existent directories are reported, and if \code{NULL}, no filtering is applied based on existence.
1518
#'
@@ -44,7 +47,7 @@
4447
#'
4548
#' @export
4649
#' @import httr2
47-
listRegisteredDirectories <- function(url, user=NULL, contains=NULL, prefix=NULL, exists=NULL) {
50+
listRegisteredDirectories <- function(url, user=NULL, contains=NULL, prefix=NULL, within=NULL, exists=NULL) {
4851
query <- character(0)
4952
if (!is.null(user) && !isFALSE(user)) {
5053
if (isTRUE(user)) {
@@ -55,6 +58,9 @@ listRegisteredDirectories <- function(url, user=NULL, contains=NULL, prefix=NULL
5558
if (!is.null(contains)) {
5659
query <- c(query, paste0("contains_path=", URLencode(contains, reserved=TRUE)))
5760
}
61+
if (!is.null(within)) {
62+
query <- c(query, paste0("within_path=", URLencode(within, reserved=TRUE)))
63+
}
5864
if (!is.null(prefix)) {
5965
query <- c(query, paste0("path_prefix=", URLencode(prefix, reserved=TRUE)))
6066
}

man/listRegisteredDirectories.Rd

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

tests/testthat/test-listRegisteredDirectories.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,29 @@ test_that("listRegisteredDirectories works as expected", {
3434
filtered <- listRegisteredDirectories(info$url, contains=tempfile())
3535
expect_identical(length(filtered), 0L)
3636

37-
# Filter by prefix.
38-
filtered <- listRegisteredDirectories(info$url, prefix=dirname(mydir))
37+
# Filter by within.
38+
filtered <- listRegisteredDirectories(info$url, within=dirname(mydir))
3939
expect_identical(all, filtered)
4040

41-
filtered <- listRegisteredDirectories(info$url, prefix=paste0(dirname(mydir), "-asdasdad"))
41+
filtered <- listRegisteredDirectories(info$url, within=paste0(dirname(mydir), "-asdasdad"))
4242
expect_identical(length(filtered), 0L)
4343

4444
# Multiple filters work.
45-
filtered <- listRegisteredDirectories(info$url, prefix=dirname(mydir), user=TRUE, contains=file.path(mydir, "diet"))
45+
filtered <- listRegisteredDirectories(info$url, within=dirname(mydir), user=TRUE, contains=file.path(mydir, "diet"))
4646
expect_identical(all, filtered)
4747

4848
# Existence filter works.
4949
tmp <- tempfile()
5050
dir.create(tmp)
5151
register(tmp, names="metadata.json", url=info$url)
5252
on.exit(deregister(tmp, url=info$url), add=TRUE, after=FALSE)
53-
filtered <- listRegisteredDirectories(info$url, prefix=tmp, exists=TRUE)
53+
filtered <- listRegisteredDirectories(info$url, within=tmp, exists=TRUE)
5454
expect_identical(normalizePath(filtered[[1]]$path), normalizePath(tmp))
5555

5656
unlink(tmp, recursive=TRUE)
57-
filtered2 <- listRegisteredDirectories(info$url, prefix=tmp, exists=FALSE)
57+
filtered2 <- listRegisteredDirectories(info$url, within=tmp, exists=FALSE)
5858
expect_identical(filtered, filtered2)
59-
filtered <- listRegisteredDirectories(info$url, prefix=tmp, exists=TRUE)
59+
filtered <- listRegisteredDirectories(info$url, within=tmp, exists=TRUE)
6060
expect_identical(length(filtered), 0L)
6161
})
6262
})()

0 commit comments

Comments
 (0)