ostrya
Ostrya [n. a botanical genus within the family Betulaceae, commonly known as ironwood tree] is a pure-Rust, async implementation of the ostree repository system, written from scratch.
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 Transactions 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.
API documentation: https://docs.rs/ostrya
Entry points
Repo::openandRepo::creategive aRepo, the handle of a repository.OpenOptionsandCreateOptionsgive aRepowith options, such as aRemotesDir.Repo::transactionbegins aTransaction, which publishes objects and refs at commit.StagingTreeandMutableTreebuild the tree of a new commit.Repo::checkout_atwrites the tree of a commit into a directory.Repo::pullcopies commits from a remote, andRepo::pull_localfrom a local repository.Repo::pull_with_reportandRepo::pull_local_with_reportalso list the refs that the pull changed.Repo::pull_with_sessioncopies commits from a remote through a session of the caller.Repo::pull_collectioncopies the refs of a collection from the remotes that serve it.Repo::export_mediacopies the commits of collection refs onto removable media.Repo::import_mediapulls collection refs from removable media, under the trust of their remotes.Erroris the error of each fallible operation ofRepo,Transaction, and the other handles.
Modules
- Read:
read,file,tree,refs, andtraverse. - Write:
transaction,mtree,staging_tree,commit,modifier,bootable. - Checkout and export:
checkout,composefs,tar, andarchive. - Pull:
pull,summary,fetch, the HTTP client ofostrya-fetch, andremote, 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 ofostrya-remote, andreceive. - 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, andspki. - 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 repositoryconfig, andconfig_group!, which defines the keys of a group. - Maintenance:
prune,fsck,diff, andupdate. - Static deltas:
DeltaSuperblock,DeltaOptions,AdvertisedDelta, andRepo::generate_static_delta.
Features
smol(default): thesmolbackend ofostrya-rt.tokio: thetokiobackend ofostrya-rt.sign-spki: thespkimodule, 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 featurespkiofostrya-sign.verify-gpg: thegpgmodule: the GPG verifier ofostrya-signwith the traitFromOstreeKeyrings, which reads the keyrings of a remote and thegpgkeys.gpgkeyring of a repository through a repository handle, and the keyring management of a remote. It turns on the featuregpgofostrya-sign.sign-gpg:GpgSigner, which signs with thegpgcommand. It turns onverify-gpg.sign-x509:X509Signer, the trait of a signer with an X.509 certificate chain for a CMS signature. Withsign-spki, alsoX509SpkiSigner,SpkiSigner::with_certificates,SpkiVerifier::from_certificates,X509Chain,x509_crls,X509ChainSigner, andSigningKey::spki_x509, the X.509 chains and CRLs that an spki signature carries in the detached metadata, the keyscertificate-chain-fileandcrl-fileof a key group, the chain removal ofRepo::delete_signatures, and the path check of the chains:X509Trust,x509_certificates,SpkiVerifier::with_x509,sign::load_x509_anchors, and the keysverification-spki-ca-file,verification-spki-intermediates-file,verification-spki-eku, andverification-spki-identityof a remote and of a trust group, and the revocation check:sign::load_x509_crls, the X.509 CRL cache ofRepo::x509_crl_contextandRepo::cache_x509_crls, and the keysverification-spki-crl-fileandverification-spki-revocationof a remote and of a trust group. A build without the feature refuses these keys.receive: thereceivemodule, the receive side of a push.push:Repo::push,Repo::push_onto, andRepo::export_stream, the push from a repository.s3: the pull from a bucket repository at ans3://address and the pull of collection refs from one, thebucketmodule with the fsck, the prune, and the summary update of a bucket repository, thes3module ofostrya-remote, and withpush, 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
let repo = open.await?;
let tip = repo.resolve_rev.await?;
Design
The API is idiomatic Rust. The bytes on disk follow the format reference of the project.
Repois cheap to clone. It holds its state in anArc, so a handle moves between tasks.Repo::opendoes the descriptor and config work once, and each clone shares it.- The runtime backend is a feature of the internal
ostrya-rtcrate:smolby default, ortokio.ContentReader,ContentWriter, and the hashing streams implement thefutures-iotraits with each backend, and thetokiotraits with thetokiofeature. A caller needs no adapter for these types. - An
AsyncReadorAsyncWritebound in an argument, as inwrite_content,import_tar, andexport_tar, is thefutures-iotrait. A caller on tokio adapts its stream withtokio_util::compat. - Each I/O entry point is an
async fn. A filter callback and an xattr callback are synchronous. Verifier::verifyis synchronous. Each verification of the crate runs it on the blocking pool ofostrya-rt.DeltaSuperblock::verifyandsign::verify_allrun it in the calling thread.rustixmakes the namespace and metadata syscalls: the opens relative to a descriptor, stat, link, rename, the xattrs, reflink,O_TMPFILEwithlinkat, the record locks, and the syncs. These calls are synchronous. They run on the blocking pool ofostrya-rtin steps that each group several calls, and not one step for each call. The content of a file streams through theFileandFileReaderofostrya-rt, over a descriptor that therustixlayer opened.- To cancel an operation, drop its future. To cancel on a signal, race the future against that signal.
- Each fallible operation of
Repo,Transaction, and the other handles returnsostrya::Error. The signing engines, the fetcher, and the typed reads and edits ofconfig::Section,config::ConfigView,config::ConfigEdit, andconfig::SectionMuthave their own error types.?converts each of them intoostrya::Error. - File content is never whole in memory. Hashing, compression, storing, checkout, and transfer read and write async streams in chunks of bounded size. Only a metadata object is held whole, because the format caps its size.
Repo,Transaction,FileObject, and the file content readers and writers areSend + Sync. Compile-time assertions in the tests hold this.
Relation to the C API
The public documentation of libostree describes a C API with GLib types. This crate maps that API to Rust as follows:
- Cancellation is the drop of a future. The crate has no
GCancellable. - A result comes back in a
Result. The crate has no out-parameters. - Options are builders and structs. The dynamic
Valueofostrya-gvariantholds commit metadata, which is an arbitrarya{sv}. - A descriptor is a
BorrowedFdor anOwnedFd. The crate has no rawdfd: i32. - The functions of the C repository object are split:
Repofor the lifecycle, the reads, the checkout, and the maintenance, andTransactionfor all writes. TheSignerandVerifiertraits make signing pluggable, and the progress handles give live counters. - RAII guards hold the scoped state: a transaction aborts when it drops without a
commit, a lock releases when its guard drops, and
Checksumis a typed value. - A key of
configis a type.repo.config().get::<repo::Fsync>()reads[core] fsyncand gives abool, and a read of a key of another group does not compile. The C API reads a key by its group name and its key name. - The remotes directory of a repository comes from
OpenOptions::remotes_dir,CreateOptions::remotes_dir, or the key[ex-ostrya] remotes-config-dirofconfig. The crate detects no system repository, so it reads/etc/ostree/remotes.donly when the caller or the key names that directory. OpenOptions::forceandOpenOptions::fallbackset a key ofconfigin memory on the handle, for example the fallbacktrueof[core] add-remotes-config-dir, whose defaultfalseputs a new remote intoconfig.