Clone the directory structure for a versioned asset into a separate location. This is typically used to prepare a new version for a lightweight upload.

cloneVersion(project, asset, version, destination, registry)

Arguments

project

String containing the project name.

asset

String containing the asset name.

version

String containing the version name.

destination

String containing a path to a destination directory at which to create the clone.

registry

String containing the path to the registry.

Value

The directory structure of the specified version is cloned to destination, and a NULL is invisibly returned.

Details

Cloning involves creating a directory at destination that has the same structure as that of the specified project-asset-version. All files in the version are represented as symlinks from destination to the corresponding file in the registry. The idea is that, when destination is used in uploadDirectory, the symlinks are converted into upload links. This allows users to create new versions very cheaply as duplicate files are not uploaded to/stored in the backend.

Users can more-or-less do whatever they want inside the cloned destination, but the symlink targets should be read-only as they refer to immutable files in the registry. If a file in destination needs to be modified, the symlink should be deleted and replaced with a new file.

See also

allocateUploadDirectory, to obtain a possible value for destination.

uploadDirectory, to prepare an upload based on the directory contents.

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 an upload. 
src <- allocateUploadDirectory(info$staging)
write(file=file.path(src, "foo"), "BAR")
uploadDirectory("test", "simple", "v1", src, staging=info$staging, url=info$url)

# Creating a clone.
dest <- tempfile()
out <- cloneVersion("test", "simple", "v1", dest, registry=info$registry)
list.files(dest, recursive=TRUE)
#> [1] "foo"
Sys.readlink(file.path(dest, "foo"))
#> [1] "/tmp/RtmpcPC1yF/file22c6da21d3a/test/simple/v1/foo"
readLines(file.path(dest, "foo"))
#> [1] "BAR"

# Files should be replaced rather than modified via the symlink:
existing <- file.path(dest, "foo")
unlink(existing) # Deleting the symlink...
write(file=existing, "YAY") # ... and writing a replacement file.