testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
Loading...
Searching...
No Matches
testcontainers::CopyToContainer Class Reference

A request to copy a host file, in-memory bytes, or a host directory tree into a container, mapping to a tar PUTed to PUT /containers/{id}/archive. More...

#include <testcontainers/CopyToContainer.hpp>

Public Member Functions

CopyToContainerwith_mode (int mode)
 Set the octal file mode of created regular-file entries (e.g.
bool is_file () const noexcept
 True if the source is a host file.
bool is_dir () const noexcept
 True if the source is a host directory tree.
const std::filesystem::path & host_path () const noexcept
const std::string & bytes () const noexcept
const std::string & target () const noexcept
int mode () const noexcept

Static Public Member Functions

static CopyToContainer host_file (std::filesystem::path host_path, std::string container_target)
 Copy a host file (host_path on the local filesystem) to container_target (an absolute path in the container, e.g.
static CopyToContainer content (std::string bytes, std::string container_target)
 Copy in-memory bytes to container_target.
static CopyToContainer host_dir (std::filesystem::path host_dir, std::string container_target)
 Copy a host directory recursively: everything under host_dir lands under container_target (an absolute directory path in the container, e.g.

Detailed Description

A request to copy a host file, in-memory bytes, or a host directory tree into a container, mapping to a tar PUTed to PUT /containers/{id}/archive.

Three sources: a host file (read at copy time), raw in-memory bytes (which may be binary, including embedded NULs), or a host directory copied recursively. Build one with a static factory, then optionally tune the file mode with the chainable setter (same style as Mount/Healthcheck).

Container-side targets are '/'-separated absolute paths regardless of the host OS. On a Windows-containers engine a drive-rooted target such as C:\dir\file (or C:/dir/file) is also accepted and treated as /dir/file, which the daemon extracts relative to C:\\endiskip.

A plain, copyable value type (no Boost/Asio/libarchive leakage).

Member Function Documentation

◆ host_file()

CopyToContainer testcontainers::CopyToContainer::host_file ( std::filesystem::path host_path,
std::string container_target )
inlinestatic

Copy a host file (host_path on the local filesystem) to container_target (an absolute path in the container, e.g.

"/tmp/foo.txt"). The file is read when the copy runs. The target's parent directory must already exist in the container.

◆ content()

CopyToContainer testcontainers::CopyToContainer::content ( std::string bytes,
std::string container_target )
inlinestatic

Copy in-memory bytes to container_target.

bytes is taken verbatim and may be binary (embedded NULs are preserved).

◆ host_dir()

CopyToContainer testcontainers::CopyToContainer::host_dir ( std::filesystem::path host_dir,
std::string container_target )
inlinestatic

Copy a host directory recursively: everything under host_dir lands under container_target (an absolute directory path in the container, e.g.

"/opt/data"), which is created — along with any missing intermediate directories — by the extraction. Empty directories are preserved. Regular files get mode() (default 0644); directories are always 0755. File symlinks are followed (their contents are copied); directory symlinks are not descended into. The tree is read when the copy runs.

◆ with_mode()

CopyToContainer & testcontainers::CopyToContainer::with_mode ( int mode)
inline

Set the octal file mode of created regular-file entries (e.g.

0644). Defaults to 0644 when unset. For a directory source this applies to every file in the tree (directories are always 0755).

◆ is_file()

bool testcontainers::CopyToContainer::is_file ( ) const
inlinenoexcept

True if the source is a host file.

◆ is_dir()

bool testcontainers::CopyToContainer::is_dir ( ) const
inlinenoexcept

True if the source is a host directory tree.

◆ host_path()

const std::filesystem::path & testcontainers::CopyToContainer::host_path ( ) const
inlinenoexcept

◆ bytes()

const std::string & testcontainers::CopyToContainer::bytes ( ) const
inlinenoexcept

◆ target()

const std::string & testcontainers::CopyToContainer::target ( ) const
inlinenoexcept

◆ mode()

int testcontainers::CopyToContainer::mode ( ) const
inlinenoexcept