[Help] WrongArgs error when using the `trans_add_pkg` function.
I'm trying to establish a transaction step by step and I keep getting a WrongArgs error when using the trans_add_pkg passing a &Package. Here's an example:
use alpm::{Alpm, Error, SigLevel, TransFlag};
fn main() -> Result<(), Error> {
let alpm = Alpm::new("/", "/var/lib/pacman")?;
alpm.register_syncdb("core", SigLevel::USE_DEFAULT)?;
alpm.register_syncdb("extra", SigLevel::USE_DEFAULT)?;
alpm.trans_init(TransFlag::NO_LOCK)?;
let pkg = alpm.localdb().pkg("tevent")?;
alpm.trans_add_pkg(pkg)?;
let pkgs = alpm.trans_add();
for pkg in pkgs {
println!("{}", pkg.name());
}
Ok(())
}
If, instead of adding a singular package, I call the sync_sysupgrade, it works fine and all upgradable packages are successfully added.
Am I doing something wrong? A WrongArgs in this case really gives me no clue of what it could be.
Thanks.
If you or anyone else is still wondering about this, it looks like this is probably the relevant assert from alpm_add_pkg (which is the lipalpm function called by trans_add_pkg):
ASSERT(pkg->origin != ALPM_PKG_FROM_LOCALDB,
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
Note that this returns WrongArgs if the package is from the local database, and that in your code snippet you grabbed the package in question from alpm.localdb().