Skip to contents

Adds a local source tarball (*.tar.gz, etc.) to an S3-hosted CRAN-like repository and updates all PACKAGES* indexes under src/contrib. The tarball is uploaded first (long cache), then the indexes are uploaded (short cache), minimizing client fetch races.

The function performs a single ETag-based concurrency check: if the index ETag has changed between read and write, it re-reads the latest index, re-merges the new package entry, and writes again.

All uploads use --acl public-read and --sse AES256 (SSE-S3) by default.

Usage

s3cran_add_source_package(bucket, local_tar, retry_on_change = TRUE)

Arguments

bucket

Character scalar. Name of the S3 bucket hosting the CRAN-like repo.

local_tar

Path to a local source package tarball (e.g. "pkg_1.2.3.tar.gz").

retry_on_change

Logical. If TRUE (default), perform one ETag recheck/ re-merge if the index changed on S3 between read and write.

Value

Invisibly, a list with:

  • uploaded_tar_key — the S3 key of the uploaded tarball

  • index_keys — character vector of the three index keys written

Details

Steps performed:

  1. Read current index from S3 (prefers PACKAGES.rds) and record its ETag.

  2. Build a one-row pkg_index from local_tar (validates filename vs DESCRIPTION).

  3. Merge the new row with the existing index (keeping all distinct (Package, Version) pairs).

  4. Write PACKAGES.rds, PACKAGES, and PACKAGES.gz to a temp dir.

  5. If retry_on_change = TRUE and the original index existed, re-check the ETag once. If it differs, re-read the latest index, re-merge, and re-write.

  6. Upload the tarball (long cache), then upload the three index files (short cache), all with public-read and SSE-S3 (AES256).

Cache headers used:

  • Tarball: Cache-Control: max-age=31536000,immutable

  • Indexes: Cache-Control: max-age=60

Requires the AWS CLI and the helpers s3cran_read_pkg_index(), s3_upload(), s3_etag(), pkg_index_from_tar(), pkg_index_bind(), and pkg_index_write().

Examples

if (FALSE) { # \dontrun{
s3cran_add_source_package(
  bucket    = "g6tr-cran-test",
  local_tar = "dist/g6tr.pkg_0.1.0.tar.gz"
)
} # }