Expand description
The object model, the on-disk format primitives, and the typed config of ostree.
A caller reads and writes the objects of an ostree repository as bytes in
the on-disk format and computes their checksums. The crate also holds the
format rules for loose paths, ref names, and new commits. It re-exports the
GVariant codec of ostrya-gvariant for the metadata of a commit. The
module config reads and edits the keys of a repository config file
through key types, with no repository handle. The crate opens no file, and
it compiles on Linux, macOS, and Windows.
§Entry points
Checksumis the SHA-256 id of an object.Commitreads and writes a commit object.DirTreeandDirMetaread and write the objects of a directory.FileHeaderis the header of a content object.Xattrsis a sorted set of extended attributes.ObjectTypeandRepoModeselect theloose_pathof an object.DeflateSinkcompresses the payload of an archive-mode content object.KeyFileparses and prints the text of the repositoryconfigfile.config::ConfigViewandconfig::ConfigEditread and edit aKeyFilethrough the key types ofconfig.Refis one ref of a repository: local, remote, or collection.RefPatternchecks and matches one ref pattern with*and**.RefSelectorselects ref names with a list of positive and negative patterns.
§Modules
base64: standard base64 for byte strings of any length.config: the typed config. It holds the traits of the groups and the keys, the text form of a value, and the typed reads and edits. It also holds the groups[core]and[ex-integrity], and the value types of the keys of the port that use no item ofostrya.filehdr: the content-object header, its framing, and its checksum.sizes: the packed entries of theostree.sizescommit metadata.varint: the LEB128 varints of the format.
§Typed config
Each key of config is a zero-sized type. The type states the group, the
key name, the value type, and the default of the key. The module
config::repo holds the key types of [core], and the module
config::ex_integrity holds the key types of [ex-integrity].
config::ConfigViewreads aKeyFilethrough the key types. It has no override, so the value in effect of a key is the value of the file or the default of the key.config::ConfigEditedits aKeyFilein memory through the key types.config_group!defines a group of a library user and its key types. The name of the group starts withex-.- A library user implements
config::Valuefor each value type of its own. - A typed read and a typed edit give
config::ConfigError.
The ostrya crate re-exports each documented item of config under
ostrya::config, and the macro as ostrya::config_group!. It adds
RepoConfig and the other groups of the port. RepoConfig applies the
overrides of a repository handle and reads the remotes of the remotes
directory.
ostrya reads and writes config with a cap of 1 MiB (1048576 bytes). A
program that links ostrya-core alone reads at most that many bytes before
KeyFile::parse. It does not write a larger document, because the open
of ostrya refuses such a file.
§Examples
use ostrya_core::{Checksum, DirMeta, ObjectType, RepoMode, Xattrs, loose_path};
// The root directory of a commit: uid 0, gid 0, mode 0755, no xattrs.
let meta = DirMeta { uid: 0, gid: 0, mode: 0o040755, xattrs: Xattrs::empty() };
let checksum = Checksum::sha256(&meta.serialize()?);
let hex = "446a0ef11b7cc167f3b603e585c7eeeeb675faa412d5ec73f62988eb0b6c5488";
assert_eq!(checksum.to_hex(), hex);
let path = loose_path(&checksum, ObjectType::DirMeta, RepoMode::Bare);
assert_eq!(path, format!("44/{}.dirmeta", &hex[2..]));A library user defines a group, reads the group and a key of [core], and
edits the key file:
use ostrya_core::config::{ConfigEdit, ConfigView, Tristate, ex_integrity, repo};
use ostrya_core::{KeyFile, RepoMode};
ostrya_core::config_group! {
/// The keys of a build tool.
pub group tool = "ex-tool" {
/// The number of parallel jobs.
Jobs: u32 = "jobs", default 4;
}
}
let mut kf = KeyFile::parse("[core]\nrepo_version=1\nmode=bare\n[ex-tool]\njobs=8\n")?;
let view = ConfigView::new(&kf);
assert_eq!(view.get::<repo::Mode>()?, RepoMode::Bare);
assert_eq!(view.get::<tool::Jobs>()?, 8);
ConfigEdit::new(&mut kf).set::<ex_integrity::Fsverity>(Tristate::No)?;
assert_eq!(kf.get_value("ex-integrity", "fsverity"), Some("no"));Re-exports§
pub use ostrya_gvariant::ArrayIter;pub use ostrya_gvariant::DictBuilder;pub use ostrya_gvariant::GvDecode;pub use ostrya_gvariant::GvEncode;pub use ostrya_gvariant::GvType;pub use ostrya_gvariant::Span;pub use ostrya_gvariant::TextError;pub use ostrya_gvariant::Type;pub use ostrya_gvariant::Value;pub use ostrya_gvariant::VariantBytes;pub use ostrya_gvariant::choose_offset_size;pub use ostrya_gvariant::from_bytes;pub use ostrya_gvariant::from_text;pub use ostrya_gvariant::offset_size_for;pub use ostrya_gvariant::to_bytes;pub use ostrya_gvariant::to_text;pub use ostrya_gvariant::to_text_unannotated;pub use ostrya_gvariant::tuple_field_from_bytes;pub use ostrya_gvariant::validate;pub use ostrya_gvariant::write_array;pub use ostrya_gvariant::write_offset;
Modules§
- base64
- Standard base64 (RFC 4648) for byte strings of any length.
- config
- The typed config API. It holds the traits of the groups and the keys, the
text form of a value, and the error of the typed reads and edits. The
module also holds the macro that defines a group, the groups
[core]and[ex-integrity], and the typed reads and edits of a key file. It holds the value types of the keys of the port that use no item ofostrya. - filehdr
- The header of a content object, its framing, and the content checksum.
- sizes
- The packed entries of the
ostree.sizescommit metadata. - varint
- The LEB128 varints of the format, as protobuf writes them.
Macros§
- config_
group - Defines one group of
configand a type for each key of the group.
Structs§
- Checksum
- A 32-byte SHA-256 checksum that names an object.
- Commit
- An owned commit object.
- Commit
Link - The parent and the root checksums of a commit, from
Commit::parse_link. - Deflate
Reader - A raw-DEFLATE encoder that reads uncompressed bytes from a source.
- Deflate
Sink - A streaming raw-DEFLATE encoder over an async writer.
- DirMeta
- An owned dirmeta object: the owner, the mode, and the xattrs of a directory.
- DirMeta
Ref - A borrowed view of a serialized dirmeta object.
- DirTree
- An owned dirtree object: the lists of child files and subdirectories.
- DirTree
Ref - A borrowed view of a serialized dirtree object.
- KeyFile
- A parsed key file, such as the repository
configfile. - Object
Name - A checksum and the type of the object that it identifies.
- Parse
RefError - The error of a ref that fails the rule of
Ref::validate, or text thatRefdoes not read. - RefPattern
- One ref pattern, with no
!. - RefSelector
- A list of positive and negative
RefPatterns. - Xattrs
- A sorted set of extended attributes, in canonical form.
- Xattrs
Ref - A borrowed view of a serialized
a(ayay)xattr set.
Enums§
- Error
- An error of the format primitives.
- Object
Type - A repository object type.
- Ref
- One ref of a repository.
- RefNamespace
- The namespace of a
Ref, asRef::namespacereturns it. - Repo
Mode - The on-disk storage mode of a repository.
- Timestamp
Error - An error of
commit_timestampand ofsource_date_epoch.
Constants§
- MAX_
COLLECTION_ ID_ LEN - The longest collection id, in bytes, that
Ref::validateaccepts. - MAX_
METADATA_ SIZE - The size limit of a metadata object: 128 MiB.
Functions§
- commit_
metadata - Returns the
a{sv}metadata dict of a new commit. - commit_
timestamp - Returns the timestamp of a new commit.
- is_
checksum_ shaped - Returns
trueifnameis 64 lowercase hex characters. - is_
collection_ id - Returns
trueifidis a collection id. - is_
ref_ component - Returns
trueifcomponentis one valid component of a part that is not a ref name. - is_
ref_ name - Returns
trueifnameis a valid ref name. - is_
ref_ name_ component - Returns
trueifcomponentis one valid component of a ref name. - is_
refspec - Returns
trueifrefspecis a valid refspec. - is_
valid_ collection_ id - Returns
trueifidis a valid collection id for a ref: it passesis_collection_idand is at mostMAX_COLLECTION_ID_LENbytes. - loose_
path - Returns the loose path of an object for a repository mode.
- ref_
binding - Returns the
ostree.ref-bindingvalue forrefs. - source_
date_ epoch - Returns the value of the
SOURCE_DATE_EPOCHenvironment variable, in seconds since the Unix epoch. - split_
collection - Splits
@ID:RESTat the first:after the@.
Type Aliases§
- Result
- The result type of the format primitives.