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.
API documentation: https://docs.rs/ostrya
Entry points
Repo::openandRepo::creategive aRepo, the handle of a repository.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_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.Erroris the error of each fallible operation of the crate.
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. - 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. - Signing:
sign,gpg, andspki. - Signature trust:
verify, the trusted keys and the trust of one pull. - Maintenance:
prune,fsck,diff,update, andconfig. - 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.verify-gpg: thegpgmodule, GPG verification and keyring management.sign-gpg:GpgSigner, which signs with thegpgcommand. It turns onverify-gpg.receive: thereceivemodule, the receive side of a push.push:Repo::push,Repo::push_onto, andRepo::export_stream, the push from a 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. - To cancel an operation, drop its future. To cancel on a signal, race the future against that signal.
- Each fallible operation returns
ostrya::Error, one enum for the crate. - 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
Result<T>. 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.