alpm-repo-db
A library and command line tool for creation and access of alpm-repo-db files (Arch Linux Package Management (ALPM) repository sync databases) and for handling alpm-repo-files entries.
Documentation
- https://alpm.archlinux.page/rustdoc/alpm_repo_db/ for development version of the crate.
- https://docs.rs/alpm-repo-db/latest/alpm_repo_db/ for released version of the crate.
Overview
The alpm-repo-db crate contains a desc module, which provides functionality for writing and parsing of [alpm-repo-desc] files.
These desc files describe the metadata of single packages in an alpm-repo-db (aka. ALPM repository sync databases).
They contain data such as the package name, version, architecture, file name, checksums, and dependencies.
It also contains a files module, which provides functionality for writing and parsing of alpm-repo-files files.
This crate provides the command line interfaces (CLI) alpm-repo-desc and alpm-repo-files, which can be used to create, parse, format and validate their respective file formats.
Examples
Library
Parsing alpm-repo-descv1 files
use std::str::FromStr;
use alpm_repo_db::desc::RepoDescFileV1;
fn main() -> Result<(), alpm_repo_db::Error> {
let desc_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst
%NAME%
example-meta
%BASE%
example-meta
%VERSION%
1.0.0-1
%DESC%
An example meta package
%CSIZE%
4634
%ISIZE%
0
%MD5SUM%
d3b07384d113edec49eaa6238ad5ff00
%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
%PGPSIG%
iHUEABYKAB0WIQRizHP4hOUpV7L92IObeih9mi7GCAUCaBZuVAAKCRCbeih9mi7GCIlMAP9ws/jU4f580ZRQlTQKvUiLbAZOdcB7mQQj83hD1Nc/GwD/WIHhO1/OQkpMERejUrLo3AgVmY3b4/uGhx9XufWEbgE=
%URL%
https://example.org/
%LICENSE%
GPL-3.0-or-later
%ARCH%
any
%BUILDDATE%
1729181726
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
"#;
let desc = RepoDescFileV1::from_str(desc_data)?;
assert_eq!(desc.name.to_string(), "example-meta");
assert_eq!(desc.arch.to_string(), "any");
Ok(())
}
Parsing alpm-repo-descv2 files
use std::str::FromStr;
use alpm_repo_db::desc::RepoDescFileV2;
fn main() -> Result<(), alpm_repo_db::Error> {
let desc_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst
%NAME%
example-meta
%BASE%
example-meta
%VERSION%
1.0.0-1
%DESC%
An example meta package
%CSIZE%
4634
%ISIZE%
0
%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
%URL%
https://example.org/
%LICENSE%
GPL-3.0-or-later
%ARCH%
any
%BUILDDATE%
1729181726
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
"#;
let desc = RepoDescFileV2::from_str(desc_data)?;
assert_eq!(desc.name.to_string(), "example-meta");
assert_eq!(desc.arch.to_string(), "any");
Ok(())
}
Working with alpm-repo-files
use std::{path::PathBuf, str::FromStr};
use alpm_repo_db::files::{RepoFiles, RepoFilesV1};
fn main() -> testresult::TestResult {
let data = r#"%FILES%
usr/
usr/bin/
usr/bin/foo
"#;
let paths = vec![
PathBuf::from("usr/"),
PathBuf::from("usr/bin/"),
PathBuf::from("usr/bin/foo"),
];
// Create a RepoFiles from a string.
let files_from_str = RepoFiles::V1(RepoFilesV1::from_str(data)?);
// Create a RepoFiles from list of paths.
let files_from_paths = RepoFiles::V1(RepoFilesV1::try_from(paths)?);
assert_eq!(files_from_str.as_ref(), files_from_paths.as_ref());
Ok(())
}
Command line
alpm-repo-desc
Create a repository desc file from CLI arguments:
alpm-repo-desc create v2 \
--file-name example-1.0.0-1-any.pkg.tar.zst \
--name example \
--base example \
--version 1.0.0-1 \
--description "An example meta package" \
--csize 4634 \
--isize 0 \
--sha256sum b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c \
--url https://example.org/ \
--license GPL-3.0-or-later \
--arch any \
--builddate 1729181726 \
--packager "Foobar McFooface <foobar@mcfooface.org>" \
--depends libfoo \
--optdepends "libbar: Optional dependency with description" \
"$REPODESC"
Format repo desc data as JSON:
alpm-repo-desc format "$REPODESC" --output-format json --pretty > "$REPODESC_JSON"
alpm-repo-files
# Create an alpm-repo-files file from an input directory.
alpm-repo-files create path/to/input/dir
# Format an alpm-repo-files file as JSON.
alpm-repo-files format --input-file path/to/repo.files --pretty
# Validate an alpm-repo-files file.
alpm-repo-files validate --input-file path/to/repo.files
Features
cli: enables the commandline interfaces for thealpm-repo-descandalpm-repo-filesbinaries._winnow-debug: enables thewinnow/debugfeature 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.