Skip to main content

Crate ostrya_core

Crate ostrya_core 

Source
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

§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 of ostrya.
  • filehdr: the content-object header, its framing, and its checksum.
  • sizes: the packed entries of the ostree.sizes commit 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].

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 of ostrya.
filehdr
The header of a content object, its framing, and the content checksum.
sizes
The packed entries of the ostree.sizes commit metadata.
varint
The LEB128 varints of the format, as protobuf writes them.

Macros§

config_group
Defines one group of config and 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.
CommitLink
The parent and the root checksums of a commit, from Commit::parse_link.
DeflateReader
A raw-DEFLATE encoder that reads uncompressed bytes from a source.
DeflateSink
A streaming raw-DEFLATE encoder over an async writer.
DirMeta
An owned dirmeta object: the owner, the mode, and the xattrs of a directory.
DirMetaRef
A borrowed view of a serialized dirmeta object.
DirTree
An owned dirtree object: the lists of child files and subdirectories.
DirTreeRef
A borrowed view of a serialized dirtree object.
KeyFile
A parsed key file, such as the repository config file.
ObjectName
A checksum and the type of the object that it identifies.
ParseRefError
The error of a ref that fails the rule of Ref::validate, or text that Ref does 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.
XattrsRef
A borrowed view of a serialized a(ayay) xattr set.

Enums§

Error
An error of the format primitives.
ObjectType
A repository object type.
Ref
One ref of a repository.
RefNamespace
The namespace of a Ref, as Ref::namespace returns it.
RepoMode
The on-disk storage mode of a repository.
TimestampError
An error of commit_timestamp and of source_date_epoch.

Constants§

MAX_COLLECTION_ID_LEN
The longest collection id, in bytes, that Ref::validate accepts.
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 true if name is 64 lowercase hex characters.
is_collection_id
Returns true if id is a collection id.
is_ref_component
Returns true if component is one valid component of a part that is not a ref name.
is_ref_name
Returns true if name is a valid ref name.
is_ref_name_component
Returns true if component is one valid component of a ref name.
is_refspec
Returns true if refspec is a valid refspec.
is_valid_collection_id
Returns true if id is a valid collection id for a ref: it passes is_collection_id and is at most MAX_COLLECTION_ID_LEN bytes.
loose_path
Returns the loose path of an object for a repository mode.
ref_binding
Returns the ostree.ref-binding value for refs.
source_date_epoch
Returns the value of the SOURCE_DATE_EPOCH environment variable, in seconds since the Unix epoch.
split_collection
Splits @ID:REST at the first : after the @.

Type Aliases§

Result
The result type of the format primitives.