RepositoryBuilder

Struct RepositoryBuilder 

Source
pub struct RepositoryBuilder<'cf> { /* private fields */ }
Expand description

Build Debian repositories from scratch.

Instances of this type are used to iteratively construct a Debian repository.

A Debian repository consists of named components holding binary packages, sources, installer packages, and metadata gluing it all together.

§Usage

Instances are constructed, preferably via Self::new_recommended().

Additional metadata about the repository is then registered using the following functions (as needed):

See https://wiki.debian.org/DebianRepository/Format for a description of what these various fields are used for.

After basic metadata is in place, .deb packages are registered against the builder via Self::add_binary_deb().

Once everything is registered against the builder, it is time to publish (read: write) the repository content.

Publishing works by first writing pool content. The pool is an area of the repository where blobs (like .deb packages) are stored. To publish the pool, call Self::publish_pool_artifacts(). This takes a DataResolver for obtaining missing pool content. Its content retrieval functions will be called for each pool path that needs to be copied to the writer. Since crate::repository::RepositoryRootReader must implement DataResolver, you can pass an instance as the DataResolver to effectively copy artifacts from another Debian repository. Note: for this to work, the source repository must have the same PoolLayout as this repository. This may not always be the case! To more robustly copy files from another repository, instantiate a crate::io::PathMappingDataResolver and call crate::io::PathMappingDataResolver::add_path_map() with the result from Self::add_binary_deb() (and similar function) to install a path mapping.

After pool content is written, indices files are derived and written. To publish these files, call Self::publish_indices(). This step uses an optional signing key to PGP sign the indices files.

For convenience, the Self::publish() method exists to perform both pool and indices publishing. It is strongly recommended to call this method instead of the lower-level methods for writing out content.

Implementations§

Source§

impl<'cf> RepositoryBuilder<'cf>

Create a new instance with recommended settings.

Files that should almost always be set (like Architectures and Components) are empty. It is recommended to use Self::new_recommended() instead.

Create a new instance with recommended settings and fields.

The arguments to this function are those that should be defined on most Debian repositories.

Calling this function is equivalent to calling Self::new_recommended_empty() then calling various .add_*() methods on the returned instance.

Source

pub fn add_architecture(&mut self, arch: impl ToString)

Register an architecture with the builder.

This defines which platform architectures there will be packages for.

Example architecture values are all, amd64, arm64, and i386.

Source

pub fn add_component(&mut self, name: impl ToString)

Register a named component with the builder.

Components describe a named subset of the repository. Example names include main, contrib, restricted, stable.

Source

pub fn add_checksum(&mut self, value: ChecksumType)

Register a checksum type to emit.

ChecksumType::Sha256 should always be used. Adding ChecksumType::Md5 is recommended for compatibility with old clients.

Source

pub fn set_suite(&mut self, value: impl ToString)

Set the Suite value.

This is often a value like stable, bionic, groovy. Some identifier that helps identify this repository.

Source

pub fn set_codename(&mut self, value: impl ToString)

Set the Codename value.

This is often a human friendly name to help identify the repository. Example values include groovy, bullseye, bionic.

Source

pub fn set_date(&mut self, value: DateTime<Utc>)

Set the time this repository was created/updated.

If not set, the current time will be used automatically.

Source

pub fn set_valid_until(&mut self, value: DateTime<Utc>)

Set the value for the Valid-Until field.

Clients should not trust this repository after this date.

Source

pub fn set_description(&mut self, value: impl ToString)

Set a human friendly description text for this repository.

Source

pub fn set_origin(&mut self, value: impl ToString)

Set a field indicating the origin of the repository.

Source

pub fn set_label(&mut self, value: impl ToString)

Set freeform text describing the repository.

Source

pub fn set_version(&mut self, value: impl ToString)

Set the version of the release.

Typically . delimited integers.

Source

pub fn set_acquire_by_hash(&mut self, value: bool)

Set the value of Acquire-By-Hash.

This should be enabled for new repositories.

Source

pub fn set_pool_layout(&mut self, layout: PoolLayout) -> Result<()>

Set the PoolLayout to use.

The layout can only be updated before content is added. Once a package has been indexed, this function will error.

Source

pub fn add_binary_deb( &mut self, component: &str, deb: &impl DebPackageReference<'cf>, ) -> Result<String>

Add a binary package .deb to this repository in the given component.

The package to add is specified as a trait to enable callers to represent Debian packages differently. For example, the trait members may be implemented by just-in-time parsing of an actual .deb file or by retrieving the data from a cache.

The specified component name must be registered with this instance or an error will occur.

Returns the pool path / Filename field that this binary package .deb will occupy in the repository.

Source

pub fn binary_package_components( &self, ) -> impl Iterator<Item = (&str, &str)> + '_

Obtain all components having binary packages.

The iterator contains 2-tuples of (component, architecture).

Source

pub fn iter_component_binary_packages( &self, component: impl ToString, architecture: impl ToString, ) -> Box<dyn Iterator<Item = &ControlParagraph<'_>> + Send + '_>

Obtain an iterator of ControlParagraph for binary packages in a given component + architecture.

This method forms the basic building block for constructing Packages files. Packages files can be built by serializing the ControlParagraph to a string/writer.

Source

pub fn iter_component_binary_package_pool_artifacts( &self, component: impl ToString, architecture: impl ToString, ) -> impl Iterator<Item = Result<BinaryPackagePoolArtifact<'_>>> + '_

Obtain an iterator of pool artifacts for binary packages that will need to exist.

Source

pub fn component_binary_packages_reader( &self, component: impl ToString, architecture: impl ToString, ) -> impl AsyncRead + '_

Obtain an AsyncRead that reads contents of a Packages file for binary packages.

This is a wrapper around Self::iter_component_binary_packages() that normalizes the ControlParagraph to data and converts it to an AsyncRead.

Source

pub fn component_binary_packages_reader_compression( &self, component: impl ToString, architecture: impl ToString, compression: Compression, ) -> Pin<Box<dyn AsyncRead + Send + '_>>

Like Self::component_binary_packages_reader() except data is compressed.

Source

pub fn binary_packages_index_readers( &self, ) -> impl Iterator<Item = IndexFileReader<'_>> + '_

Obtain IndexFileReader for each logical Packages file.

Source

pub fn index_file_readers( &self, ) -> impl Iterator<Item = IndexFileReader<'_>> + '_

Obtain all IndexFileReader to be published.

Each item corresponds to a logical item in an [In]Release.

Source

pub fn iter_binary_packages_pool_artifacts( &self, ) -> impl Iterator<Item = Result<BinaryPackagePoolArtifact<'_>>> + '_

Obtain records describing pool artifacts needed to support binary packages.

Source

pub async fn publish_pool_artifacts<F>( &self, resolver: &impl DataResolver, writer: &impl RepositoryWriter, threads: usize, progress_cb: &Option<F>, ) -> Result<()>
where F: Fn(PublishEvent),

Publish artifacts to the pool.

The pool is the area of a Debian repository holding files like the .deb packages.

Content must be published to the pool before indices data is written, otherwise there is a race condition where the indices could refer to files not yet in the pool.

Source

pub fn create_release_file( &self, indices: impl Iterator<Item = (String, (u64, MultiContentDigest))>, ) -> Result<ReleaseFile<'_>>

Derive a ReleaseFile representing the content of the Release file.

This takes an iterable describing indices files. This iterable is typically derived from Self::index_file_readers().

Source

pub async fn publish_indices<F, PW>( &self, writer: &impl RepositoryWriter, path_prefix: Option<&str>, threads: usize, progress_cb: &Option<F>, signing_key: Option<(&impl SecretKeyTrait, PW)>, ) -> Result<()>
where F: Fn(PublishEvent), PW: FnOnce() -> String,

Publish index files.

Repository index files describe the contents of the repository. Index files are referred to by the InRelease and Release files.

Indices should only be published after pool artifacts are published. Otherwise there is a race condition where an index file could refer to a file in the pool that does not exist.

Source

pub async fn publish<F, PW>( &self, writer: &impl RepositoryWriter, resolver: &impl DataResolver, distribution_path: &str, threads: usize, progress_cb: &Option<F>, signing_key: Option<(&impl SecretKeyTrait, PW)>, ) -> Result<()>
where F: Fn(PublishEvent), PW: FnOnce() -> String,

Publish the repository to the given RepositoryWriter.

This is the main function for writing out the desired state in this builder.

Publishing effectively works in 3 phases:

  1. Publish missing pool artifacts.
  2. Publish indices files (e.g. Packages lists).
  3. Publish the InRelease and Release file.

writer is a RepositoryWriter used to perform I/O for writing output files. resolver is a DataResolver for resolving pool paths. It will be consulted to obtain paths of .deb and other pool files. distribution_path is the relative path under writer to write indices files under. It typically begins with dists/. e.g. dists/bullseye. This value becomes the directory with the generated InRelease file. threads is the number of parallel threads to use for I/O. progress_cb provides an optional function to receive progress updates. signing_key provides a signing key for PGP signing and an optional function to obtain the password to unlock that key.

To set progress_cb or signing_key to None, you’ll need to use the turbofish operator to specify the type. e.g. &Option<fn(PublishEvent)>::None for progress_cb and Option::<(&pgp::SignedSecretKey, fn() -> String)>::None for signing_key. Alternatively, use the NO_PROGRESS_CB or NO_SIGNING_KEY module constants to avoid some typing.

Trait Implementations§

Source§

impl<'cf> Debug for RepositoryBuilder<'cf>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'cf> Default for RepositoryBuilder<'cf>

Source§

fn default() -> RepositoryBuilder<'cf>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'cf> Freeze for RepositoryBuilder<'cf>

§

impl<'cf> RefUnwindSafe for RepositoryBuilder<'cf>

§

impl<'cf> Send for RepositoryBuilder<'cf>

§

impl<'cf> Sync for RepositoryBuilder<'cf>

§

impl<'cf> Unpin for RepositoryBuilder<'cf>

§

impl<'cf> UnwindSafe for RepositoryBuilder<'cf>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more