diff --git a/DESCRIPTION b/DESCRIPTION index 5e98762..769c3ca 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gobbler -Version: 0.3.10 -Date: 2024-10-18 +Version: 0.3.11 +Date: 2025-01-28 Title: Interface to the gobbler service Description: Friendly interface to the gobbler service. diff --git a/NAMESPACE b/NAMESPACE index 2c865b0..ced0a8d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(listProjects) export(listVersions) export(refreshLatest) export(refreshUsage) +export(reindexVersion) export(rejectProbation) export(removeAsset) export(removeProject) diff --git a/R/reindexVersion.R b/R/reindexVersion.R new file mode 100644 index 0000000..d9f8d09 --- /dev/null +++ b/R/reindexVersion.R @@ -0,0 +1,37 @@ +#' Reindex a versioned asset +#' +#' Reindex a version of an asset of a project from the registry. +#' This regenerates all of the internal \code{..manifest} and \code{..links} files. +#' +#' @param project String containing the project to remove. +#' @param asset String containing the asset to remove. +#' @param version String containing the version of the asset to remove. +#' @inheritParams createProject +#' +#' @return \code{NULL} is invisibly returned if the version was successfully reindexed. +#' +#' @author Aaron Lun +#' +#' @examples +#' info <- startGobbler() +#' removeProject("test", info$staging, url=info$url) # start with a clean slate. +#' createProject("test", info$staging, url=info$url) +#' +#' # Mocking up a version if it doesn't already exist. +#' src <- allocateUploadDirectory(info$staging) +#' write(file=file.path(src, "foo"), "BAR") +#' uploadDirectory("test", "simple", "v1", src, staging=info$staging, url=info$url) +#' fetchManifest("test", "simple", "v1", registry=info$registry, url=info$url) +#' +#' # Let's add a new file directly to the directory. +#' write(file=file.path(info$registry, "test", "simple", "v1", "whee"), "stuff") +#' +#' # And reindexing the version. +#' reindexVersion("test", "simple", "v1", staging=info$staging, url=info$url) +#' fetchManifest("test", "simple", "v1", registry=info$registry, url=info$url) +#' +#' @export +reindexVersion <- function(project, asset, version, staging, url) { + dump_request(staging, url, "reindex_version", list(project=project, asset=asset, version=version)) + invisible(NULL) +} diff --git a/R/startGobbler.R b/R/startGobbler.R index 9751b62..aba9f25 100644 --- a/R/startGobbler.R +++ b/R/startGobbler.R @@ -36,7 +36,7 @@ #' #' @export #' @importFrom utils download.file -startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.3.7", overwrite = FALSE) { +startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.3.8", overwrite = FALSE) { if (!is.null(running$active)) { return(list(new=FALSE, staging=running$staging, registry=running$registry, port=running$port, url=assemble_url(running$port))) } diff --git a/man/reindexVersion.Rd b/man/reindexVersion.Rd new file mode 100644 index 0000000..5186945 --- /dev/null +++ b/man/reindexVersion.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reindexVersion.R +\name{reindexVersion} +\alias{reindexVersion} +\title{Reindex a versioned asset} +\usage{ +reindexVersion(project, asset, version, staging, url) +} +\arguments{ +\item{project}{String containing the project to remove.} + +\item{asset}{String containing the asset to remove.} + +\item{version}{String containing the version of the asset to remove.} + +\item{staging}{String containing the path to the staging directory.} + +\item{url}{String containing the URL of the gobbler REST API.} +} +\value{ +\code{NULL} is invisibly returned if the version was successfully reindexed. +} +\description{ +Reindex a version of an asset of a project from the registry. +This regenerates all of the internal \code{..manifest} and \code{..links} files. +} +\examples{ +info <- startGobbler() +removeProject("test", info$staging, url=info$url) # start with a clean slate. +createProject("test", info$staging, url=info$url) + +# Mocking up a version if it doesn't already exist. +src <- allocateUploadDirectory(info$staging) +write(file=file.path(src, "foo"), "BAR") +uploadDirectory("test", "simple", "v1", src, staging=info$staging, url=info$url) +fetchManifest("test", "simple", "v1", registry=info$registry, url=info$url) + +# Let's add a new file directly to the directory. +write(file=file.path(info$registry, "test", "simple", "v1", "whee"), "stuff") + +# And reindexing the version. +reindexVersion("test", "simple", "v1", staging=info$staging, url=info$url) +fetchManifest("test", "simple", "v1", registry=info$registry, url=info$url) + +} +\author{ +Aaron Lun +} diff --git a/man/startGobbler.Rd b/man/startGobbler.Rd index 62f81b0..de7202f 100644 --- a/man/startGobbler.Rd +++ b/man/startGobbler.Rd @@ -10,7 +10,7 @@ startGobbler( registry = tempfile(), port = NULL, wait = 1, - version = "0.3.7", + version = "0.3.8", overwrite = FALSE ) diff --git a/tests/testthat/test-reindexVersion.R b/tests/testthat/test-reindexVersion.R new file mode 100644 index 0000000..8f98a29 --- /dev/null +++ b/tests/testthat/test-reindexVersion.R @@ -0,0 +1,23 @@ +# library(testthat); library(gobbler); source("test-reindexVersion.R") + +info <- startGobbler() +removeProject("test-R-reindex", staging=info$staging, url=info$url) +createProject("test-R-reindex", staging=info$staging, url=info$url) + +test_that("reindexing functions work as expected", { + src <- allocateUploadDirectory(info$staging) + write(file=file.path(src, "foo"), "BAR") + uploadDirectory("test-R-reindex", "simple", "v1", src, staging=info$staging, url=info$url) + + # Let's add a new file directly to the directory. + write(file=file.path(info$registry, "test-R-reindex", "simple", "v1", "whee"), "stuff") + + # This does not show up in the manifest... + man <- fetchManifest("test-R-reindex", "simple", "v1", registry=info$registry, url=info$url) + expect_identical(names(man), "foo") + + # Until we reindex the version. + reindexVersion("test-R-reindex", "simple", "v1", staging=info$staging, url=info$url) + man <- fetchManifest("test-R-reindex", "simple", "v1", registry=info$registry, url=info$url) + expect_identical(names(man), c("foo", "whee")) +})