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.
```rust use pkgsrc::pmatch::pkg_match;
// simple match asserteq!(pkgmatch("foobar-1.0", "foobar-1.0"), true); asserteq!(pkgmatch("foobar-1.0", "foobar-1.1"), false);
// dewey comparisons asserteq!(pkgmatch("foobar>=1.0", "foobar-1.1"), true); asserteq!(pkgmatch("foobar>=1.1", "foobar-1.0"), false);
// alternate matches asserteq!(pkgmatch("{foo,bar}>=1.0", "foo-1.1"), true); asserteq!(pkgmatch("{foo,bar}>=1.0", "bar-1.1"), true); asserteq!(pkgmatch("{foo,bar}>=1.0", "moo-1.1"), false);
// globs asserteq!(pkgmatch("foo-[0-9]", "foo-1.0"), true); assert_eq!(pkg_match("fo?-[0-9]", "foo-1.0"), true); asserteq!(pkgmatch("fo-[0-9]", "foobar-1.0"), true); ```
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.