ostrya 0.19.0

Pure-Rust async reimplementation of the ostree repository library
Documentation
#![forbid(unsafe_code)]
#![cfg_attr(docsrs, feature(doc_cfg))]

//! An async, pure-Rust library that reads and writes ostree repositories.
//!
//! A user opens a repository, writes commits in transactions, reads and checks
//! out trees, and pulls, pushes, signs, and prunes. The bytes on disk are the
//! bytes that the `ostree` command writes. Many [`Transaction`]s can write to
//! one repository at once in one process.
//!
//! As an extension, the crate also has a push protocol over HTTP and over ssh.
//! With the `push` feature, `Repo::push` sends commits to a remote, and
//! `Repo::push_onto` asks a remote to commit the tree of a local commit. With
//! the `receive` feature, the `receive` module takes a push on the server side.
//! With the `push` and `s3` features, `Repo::push_to_bucket` writes commits to
//! a bucket repository in an S3 bucket, `BucketRepo::push_tree` writes a local
//! directory to one as a new commit, and `BucketRepo::init` creates one.
//!
//! # Entry points
//! - [`Repo::open`] and [`Repo::create`] give a [`Repo`], the handle of a repository.
//! - [`OpenOptions`] and [`CreateOptions`] give a [`Repo`] with options, such as a [`RemotesDir`].
//! - [`Repo::transaction`] begins a [`Transaction`], which publishes objects and refs at commit.
//! - [`StagingTree`] and [`MutableTree`] build the tree of a new commit.
//! - [`Repo::checkout_at`] writes the tree of a commit into a directory.
//! - [`Repo::pull`] copies commits from a remote, and [`Repo::pull_local`] from a local repository.
//! - [`Repo::pull_with_report`] and [`Repo::pull_local_with_report`] also list the refs that the pull changed.
//! - [`Repo::pull_with_session`] copies commits from a remote through a session of the caller.
//! - [`Repo::pull_collection`] copies the refs of a collection from the remotes that serve it.
//! - [`Repo::export_media`] copies the commits of collection refs onto removable media.
//! - [`Repo::import_media`] pulls collection refs from removable media, under the trust of their remotes.
//! - [`Error`] is the error of each fallible operation of `Repo`, `Transaction`, and the other handles.
//!
//! # Modules
//! - Read: [`read`], [`file`](mod@file), [`tree`], [`refs`], and [`traverse`].
//! - Write: [`transaction`], [`mtree`], [`staging_tree`], [`commit`], [`modifier`], [`bootable`].
//! - Checkout and export: [`checkout`], [`composefs`], [`tar`], and [`archive`].
//! - Pull: [`pull`], [`summary`], [`fetch`], the HTTP client of `ostrya-fetch`, and [`remote`], which holds the session of a pull over HTTP, over ssh, or over a pair of byte streams.
//! - Removable media: [`media`], the export of collection refs onto a mounted volume, and the import from it.
//! - Push and receive: [`remote`], the wire protocol of `ostrya-remote`, and `receive`.
//! - Client access: [`access`], the client groups and the server settings of the config, the claims of a client certificate, and the read rights of a client.
//! - Remote resolution: [`endpoint`], which reads the keys and files of a remote for a pull or a push.
//! - Bucket repositories: `bucket`, a repository in an S3 bucket, with the init, the writer lock, the listing of the objects, the fsck, the prune, and the summary update.
//! - Signing: [`sign`], `gpg`, and `spki`.
//! - Signature trust: [`verify`], the trusted keys, the trust of one pull, and the verifiers of one remote.
//! - Config: [`config`], a type for each key of the repository `config`, and [`config_group!`], which defines the keys of a group.
//! - Maintenance: [`prune`], [`fsck`], [`diff`], and [`update`].
//! - Static deltas: [`DeltaSuperblock`], [`DeltaOptions`], [`AdvertisedDelta`], and [`Repo::generate_static_delta`].
//!
//! # Features
//! - `smol` (default): the `smol` backend of `ostrya-rt`.
//! - `tokio`: the `tokio` backend of `ostrya-rt`.
//! - `sign-spki`: the `spki` module, the spki signing engine with each of its key types: ECDSA P-256, ECDSA P-384, Ed25519, RSA, ML-DSA-44, ML-DSA-65, and ML-DSA-87, and the 12 parameter sets of SLH-DSA. It turns on the feature `spki` of `ostrya-sign`.
//! - `verify-gpg`: the `gpg` module: the GPG verifier of `ostrya-sign` with the trait `FromOstreeKeyrings`, which reads the keyrings of a remote and the `gpgkeys.gpg` keyring of a repository through a repository handle, and the keyring management of a remote. It turns on the feature `gpg` of `ostrya-sign`.
//! - `sign-gpg`: `GpgSigner`, which signs with the `gpg` command. It turns on `verify-gpg`.
//! - `sign-x509`: `X509Signer`, the trait of a signer with an X.509 certificate chain for a CMS signature. With `sign-spki`, also `X509SpkiSigner`, `SpkiSigner::with_certificates`, `SpkiVerifier::from_certificates`, `X509Chain`, `x509_crls`, `X509ChainSigner`, and `SigningKey::spki_x509`, the X.509 chains and CRLs that an spki signature carries in the detached metadata, the keys `certificate-chain-file` and `crl-file` of a key group, the chain removal of `Repo::delete_signatures`, and the path check of the chains: `X509Trust`, `x509_certificates`, `SpkiVerifier::with_x509`, `sign::load_x509_anchors`, and the keys `verification-spki-ca-file`, `verification-spki-intermediates-file`, `verification-spki-eku`, and `verification-spki-identity` of a remote and of a trust group, and the revocation check: `sign::load_x509_crls`, the X.509 CRL cache of `Repo::x509_crl_context` and `Repo::cache_x509_crls`, and the keys `verification-spki-crl-file` and `verification-spki-revocation` of a remote and of a trust group. A build without the feature refuses these keys.
//! - `receive`: the `receive` module, the receive side of a push.
//! - `push`: `Repo::push`, `Repo::push_onto`, and `Repo::export_stream`, the push from a repository.
//! - `s3`: the pull from a bucket repository at an `s3://` address and the pull of collection refs from one, the `bucket` module with the fsck, the prune, and the summary update of a bucket repository, the `s3` module of `ostrya-remote`, and with `push`, the push of commits and of a local directory to a bucket repository.
//! - `lzma-static`: xz built from source and linked statically, with no runtime liblzma.
//!
//! # Examples
//! ```no_run
//! # async fn run() -> ostrya::Result<()> {
//! let repo = ostrya::Repo::open("/srv/repo".as_ref()).await?;
//! let tip = repo.resolve_rev("exampleos/stable", false).await?;
//! # Ok(()) }
//! ```

pub mod repo;
pub mod transaction;

pub mod access;
pub mod archive;
pub mod bootable;
mod bspatch;
#[cfg(feature = "s3")]
pub mod bucket;
pub mod checkout;
pub mod commit;
pub mod composefs;
pub mod config;
mod delta;
mod deltagen;
pub mod diff;
pub mod endpoint;
pub mod error;
pub use ostrya_fetch as fetch;
pub use ostrya_remote as remote;
pub mod file;
pub mod fsck;
#[cfg(feature = "verify-gpg")]
pub mod gpg;
mod hashing;
mod image_commit;
mod inflate;
mod ingest;
mod jobs;
mod lock;
pub mod media;
pub mod modifier;
pub mod mtree;
mod object;
mod overlay;
mod pattern;
pub mod prune;
pub mod pull;
#[cfg(feature = "push")]
mod push_repo;
pub mod read;
#[cfg(feature = "receive")]
pub mod receive;
pub mod refs;
mod related;
mod remotes_dir;
mod repo_fs;
mod rollsum;
mod send;
#[cfg(any(feature = "receive", all(feature = "push", feature = "s3")))]
mod server_commit;
pub mod sign;
#[cfg(feature = "sign-spki")]
pub mod spki {
    //! The spki signing engine: ECDSA P-256 and P-384, Ed25519, RSA PKCS#1
    //! v1.5, ML-DSA, and SLH-DSA signatures, with SPKI public keys.
    pub use ostrya_sign::{
        SpkiSigner, SpkiVerifier, spki_public_keys, spki_secret_key_lines, spki_secret_keys,
    };
    #[cfg(feature = "sign-x509")]
    pub use ostrya_sign::{
        X509Chain, X509ChainSigner, X509SpkiSigner, X509Trust, x509_certificates, x509_crls,
    };
}
mod staging;
pub mod staging_tree;
pub mod summary;
pub mod tar;
mod tombstone;
pub mod traverse;
pub mod tree;
pub mod update;
pub mod verify;
mod write;

#[doc(hidden)]
pub use archive::{ArchiveAnswer, ArchiveHead, ArchiveView};
#[doc(hidden)]
pub use bootable::{BootableMetadata, BootableRefusal};
#[cfg(feature = "s3")]
#[doc(hidden)]
pub use bucket::{
    BucketFinding, BucketFindingKind, BucketFsckOptions, BucketFsckReport, BucketPruneOptions,
    BucketPruneReport, BucketPushOutcome, BucketRepo, BucketSummaryOptions, BucketSummaryReport,
    BucketWriteOptions, LockHolder, LockOperation, ObjectListing, WriterLock,
};
#[doc(hidden)]
pub use checkout::{CheckoutFilterFn, CheckoutMode, CheckoutOptions, OverwriteMode};
#[doc(hidden)]
pub use commit::{CheckedAttachments, CommitOptions};
#[doc(hidden)]
pub use composefs::{
    COMPOSEFS_DIGEST_KEY, ComposefsEntryFn, ComposefsOptions, EntryKind, VerityPolicy,
};
#[doc(hidden)]
pub use config::{
    MinFreeSpace, RemoteSource, RepoConfig, SignVerify, SizeSpec, SizeUnit, Tristate,
    valid_remote_name,
};
pub use delta::{
    DeltaEndianness, DeltaFallback, DeltaOpCounts, DeltaPart, DeltaPartStats, DeltaSuperblock,
};
pub use deltagen::{DeltaOptions, static_delta_relative_dir};
#[doc(hidden)]
pub use diff::{DiffChange, DiffEntry, DiffOptions, DiffSide, DiffStats};
#[doc(hidden)]
pub use error::{Error, Result};
#[doc(hidden)]
pub use fetch::{
    BasicAuth, BearerToken, Body, ClientIdentity, FetchRequest, Fetched, Fetcher, FetcherOptions,
    LowSpeed, Priority, Protocol, Proxy, Target, TlsOptions, TrustRoots, UploadBody, UploadMethod,
    UploadRequest, UploadWriter, Uploaded, Validators,
};
#[doc(hidden)]
pub use file::{ContentReader, FileKind, FileObject};
#[doc(hidden)]
pub use fsck::{
    FsckAttachmentError, FsckAttachmentErrorKind, FsckBindingError, FsckBindingErrorKind,
    FsckError, FsckErrorKind, FsckFailure, FsckOptions, FsckPhase, FsckReport,
};
#[cfg(feature = "sign-gpg")]
#[doc(hidden)]
pub use gpg::GpgSigner;
#[cfg(feature = "verify-gpg")]
#[doc(hidden)]
pub use gpg::{FromOstreeKeyrings, GpgKey, GpgVerifier};
pub use hashing::{HashingReader, HashingWriter, VerifyingReader};
pub use image_commit::{
    COMPOSEFS_RELATION, ComposefsImage, ComposefsImageDefect, ComposefsImageSource,
    ComposefsSupplementAdd,
};
pub use ingest::remove_source_tree;
pub use lock::LockKind;
#[doc(hidden)]
pub use media::{
    MediaExportOptions, MediaExportReport, MediaImportOptions, MediaImportReport, MediaSkip,
};
#[doc(hidden)]
pub use modifier::{
    CommitModifier, CommitModifierFlags, DevInoCache, FilterFn, FilterResult, LabelFn, ModeFn,
    XattrFn,
};
#[doc(hidden)]
pub use mtree::MutableTree;
pub use object::MAX_METADATA_SIZE;
pub use ostrya_composefs::{Image, Metadata};
#[doc(hidden)]
pub use ostrya_core::__config_group;
pub use ostrya_core::base64;
#[doc(no_inline)]
pub use ostrya_core::config_group;
pub use ostrya_core::{
    Checksum, Commit, DictBuilder, DirMeta, DirTree, KeyFile, ObjectName, ObjectType,
    ParseRefError, Ref, RefNamespace, RefPattern, RefSelector, RepoMode, Span, TextError, Type,
    Value, Xattrs, from_bytes, from_text, is_checksum_shaped, is_collection_id,
    is_valid_collection_id, loose_path, source_date_epoch, split_collection, to_text,
    to_text_unannotated,
};
pub use ostrya_remote::proto::{
    MAX_REF_ENTRY_LEN, MAX_REF_ENTRY_PARTS, MAX_REF_LISTING, MAX_REF_PATTERNS,
};
#[doc(hidden)]
pub use pattern::ReceivePattern;
pub use pattern::ReceiveSelector;
#[doc(hidden)]
pub use prune::{PruneOptions, PruneStats, WeakRefFilter, WeakRefFilterFn};
#[doc(hidden)]
pub use pull::{
    CollectionPullEvent, CollectionPullOptions, CollectionPullRef, CollectionPullStats, PullFlags,
    PullOptions, PullProgress, PullProgressSnapshot, PullReport, PullStats, PullVerify, RefChange,
    TimestampCheck, commit_operand,
};
#[cfg(feature = "push")]
pub use push_repo::{ExportStreamOptions, PushOntoOptions, RepoPushOptions, is_push_address};
#[doc(hidden)]
pub use read::{CommitSizes, CommitState, MetadataReader};
#[cfg(feature = "receive")]
#[doc(hidden)]
pub use receive::{
    HookFuture, HookRefusal, HostEntry, ReceiveCommit, ReceiveHooks, ReceivePolicies,
    ReceivePolicy, ReceiveRefOutcome, ReceiveRefUpdate, ReceiveReport, ReceiveServerCommit,
    ReceiveService, ReceiveStep, ReceiveVerify, ReceiveWarning, StreamPolicy, StreamRule,
    UpdatePlan,
};
#[doc(hidden)]
pub use refs::{CollectionRefEntry, RefAlias, validate_refspec};
pub use related::{CommitRelations, RelationField, RelationWarning};
#[doc(hidden)]
pub use repo::{CreateOptions, OpenOptions, RemotesDir, Repo};
pub use send::{SendEvent, SendEventFn, SendOptions};
#[cfg(feature = "sign-x509")]
#[doc(hidden)]
pub use sign::X509Signer;
#[doc(hidden)]
pub use sign::{
    DummySigner, DummyVerifier, Ed25519Signer, Ed25519Verifier, FromSystemKeys, SignFuture,
    SignKeys, SignatureInfo, Signer, SigningKey, Verifier, VerifyOutcome, load_sign_keys,
    load_sign_keys_from,
};
#[cfg(feature = "sign-spki")]
#[doc(hidden)]
pub use spki::{
    SpkiSigner, SpkiVerifier, spki_public_keys, spki_secret_key_lines, spki_secret_keys,
};
#[cfg(all(feature = "sign-x509", feature = "sign-spki"))]
#[doc(hidden)]
pub use spki::{
    X509Chain, X509ChainSigner, X509SpkiSigner, X509Trust, x509_certificates, x509_crls,
};
#[doc(hidden)]
pub use staging_tree::{
    MergeOptions, RootDirmeta, StagedFileWriter, StagingEntry, StagingLookup, StagingTree,
};
#[doc(hidden)]
pub use summary::{
    AdvertisedDelta, RefListing, Summary, SummaryOptions, SummaryRef, SummaryReport,
};
#[doc(hidden)]
pub use tar::{TarExportOptions, TarImportOptions, TarRename};
#[doc(hidden)]
pub use transaction::{ContentWriter, FileMeta, Transaction, TransactionStats};
#[doc(hidden)]
pub use tree::{RepoTree, TreeEntry};
#[doc(hidden)]
pub use update::UpdateGuard;
#[doc(hidden)]
pub use verify::{PullTrust, TrustedKeys};

/// Removes the staging directories of the live transactions of this process.
///
/// A [`Transaction`] removes its staging directory when it commits, aborts, or
/// drops. [`std::process::exit`] runs no destructor. If a process ends that way
/// with a live transaction, its `tmp/staging-<boot-id>-XXXXXX` directory and
/// the sibling lock file stay. The reaper of a later transaction removes them.
///
/// A caller that ends the process with no unwind calls this function
/// immediately before the end. `tmp/` is then in the state that a return with
/// an unwind leaves.
///
/// The call removes the staging directory and the sibling lock file of each
/// live transaction in the process. A transaction that runs after the call
/// finds its staged objects gone, so the call is correct only when the
/// process is about to end. [`Transaction`] describes the staging directory
/// and the reaper.
pub fn reap_process_staging() {
    staging::reap_owned();
}