pkgsrc-rs

Build Status Crates.io Documentation

A Rust interface to pkgsrc packages and the pkg_install pkgdb.

This is being developed alongside pm, a Rust implementation of a pkgsrc package manager. Anything that handles lower level pkg_install routines will be placed here.

Example

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.

```rust 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(())

} ```

Status

License

This project is licensed under the ISC license.

Testing/compatibility notes

Generate list of dependency matches.

bash sqlite3 /var/db/pkgin/pkgin.db 'SELECT remote_deps_dewey FROM remote_deps' | sort | uniq > pkgdeps.txt

Generate list of package names

bash 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

bash 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.