Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

alpm-db

A library for Arch Linux Package Management (ALPM) system databases.

Documentation

Overview

alpm-db crate contains desc module, which provides functionality for writing and parsing of ALPM DB desc files.

These desc files describe the metadata of installed packages on a system relying on ALPM. They contain fields such as the package name, version, architecture, and dependencies.

It also contains a commandline interface (CLI) binary alpm-db-desc, which can be used to create, parse, format and validate ALPM DB desc files.

Examples

Library

Parsing alpm-db-descv1 files:

use std::str::FromStr;
use alpm_db::desc::DbDescFileV1;

fn main() -> Result<(), alpm_db::Error> {
let desc_data = r#"%NAME%
foo

%VERSION%
1.0.0-1

%BASE%
foo

%DESC%
An example package

%URL%
https://example.org

%ARCH%
x86_64

%BUILDDATE%
1733737242

%INSTALLDATE%
1733737243

%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>

%SIZE%
123

%VALIDATION%
pgp

"#;

let desc = DbDescFileV1::from_str(desc_data)?;
assert_eq!(desc.name.to_string(), "foo");
assert_eq!(desc.arch.to_string(), "x86_64");
Ok(())
}

Parsing alpm-db-descv2 files:

use std::str::FromStr;
use alpm_db::desc::DbDescFileV2;

fn main() -> Result<(), alpm_db::Error> {
let desc_data = r#"%NAME%
foo

%VERSION%
1.0.0-1

%BASE%
foo

%DESC%
An example package

%URL%
https://example.org

%ARCH%
x86_64

%BUILDDATE%
1733737242

%INSTALLDATE%
1733737243

%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>

%SIZE%
123

%VALIDATION%
pgp

%XDATA%
pkgtype = pkg
key2 = value2
"#;

let desc = DbDescFileV2::from_str(desc_data)?;
assert_eq!(desc.name.to_string(), "foo");
assert_eq!(desc.arch.to_string(), "x86_64");
assert_eq!(desc.xdata.len(), 2);
Ok(())
}

Commandline

Create a database desc file from CLI arguments:

alpm-db-desc create v2 \
    --name foo \
    --version 1.0.0-1 \
    --base foo \
    --description "An example package" \
    --url https://example.org/ \
    --arch x86_64 \
    --builddate 1733737242 \
    --installdate 1733737243 \
    --packager "Foobar McFooface <foobar@mcfooface.org>" \
    --size 123 \
    --validation pgp \
    --optdepends libfoo,libbar \
    --optdepends "libdesc: Optional dependency with description" \
    --xdata pkgtype=pkg \
    "$DBDESC"

The output file ($DBDESC) contains the desc data in alpm-db-descv1 format.

Format db desc data as JSON:

alpm-db-desc format "$DBDESC" --output-format json --pretty > "$DBDESC_JSON"

The output file ($DBDESC_JSON) contains the structured JSON representation of the parsed desc data.

Features

  • cli: enables the commandline interface for the alpm-db-desc binary.
  • _winnow-debug: enables the winnow/debug feature for step-by-step parser debugging.

Contributing

Please refer to the contribution guidelines to learn how to contribute to this project.

License

This project can be used under the terms of the Apache-2.0 or MIT. Contributions to this project, unless noted otherwise, are automatically licensed under the terms of both of those licenses.