Crates.io | pkgsrc |
lib.rs | pkgsrc |
version | 0.4.0 |
source | src |
created_at | 2019-08-12 15:37:42.776675 |
updated_at | 2024-10-23 16:29:38.29963 |
description | Library for interacting with a pkgsrc installation |
homepage | https://github.com/jperkin/pkgsrc-rs |
repository | https://github.com/jperkin/pkgsrc-rs |
max_upload_size | |
id | 156152 |
size | 1,384,117 |
A Rust interface to the pkgsrc infrastructure, binary package archives, and the pkg_install pkgdb.
This is being developed alongside:
You should expect things to change over time as each interface adapts to better support these utilities, though I will still make sure to use semver versioning accordingly to avoid gratuitously breaking downstream utilities.
This is a simple implementation of pkg_info(8)
that supports the default
output format, i.e. list all currently installed packages and their single-line
comment.
use pkgsrc::{MetadataEntry, PkgDB};
use std::path::Path;
fn main() -> Result<(), std::io::Error> {
let pkgdb = PkgDB::open(Path::new("/var/db/pkg"))?;
for pkg in pkgdb {
let pkg = pkg?;
println!("{:20} {}",
pkg.pkgname(),
pkg.read_metadata(MetadataEntry::Comment)?
.trim()
);
}
Ok(())
}
pkg_match() is implemented and verified to be correct against a large input of matches.
Metadata handles "+*" files contained in an archive and is able to verify that the archive contains a valid package.
PkgDB handles local pkg databases, currently supporting the regular file-backed repository, but with flexible support for future sqlite3-backed repositories.
Summary handles pkg_summary(5) parsing and generation.
This project is licensed under the ISC license.
Generate list of dependency matches.
sqlite3 /var/db/pkgin/pkgin.db 'SELECT remote_deps_dewey FROM remote_deps' | sort | uniq > pkgdeps.txt
Generate list of package names
sqlite3 /var/db/pkgin/pkgin.db 'SELECT fullpkgname FROM remote_pkg' >pkgnames.txt
Implement the following algorithm in both C and Rust and compare output
while read pattern; do
while read pkg; do
pkg_match "${pattern}" "${pkg}"
printf "%s\t%s\t%s", ${pattern}, ${pkg}, $? >> outfile
done < pkgnames.txt
done < pkgdeps.txt
As an added bonus, the C version took 55 seconds to generate 158,916,879 matches, whilst the Rust version took 42 seconds.