-
Notifications
You must be signed in to change notification settings - Fork 22
/
transaction.rs
39 lines (30 loc) · 1.23 KB
/
transaction.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use alpm::{Alpm, Error, SigLevel, TransFlag};
fn main() {
let mut handle = Alpm::new("/", "tests/db").unwrap();
let db = handle.register_syncdb_mut("core", SigLevel::NONE).unwrap();
db.add_server("https://ftp.rnl.tecnico.ulisboa.pt/pub/archlinux/core/os/x86_64")
.unwrap();
let core = handle
.syncdbs()
.iter()
.find(|db| db.name() == "core")
.unwrap();
let pkg = core.pkg("filesystem").unwrap();
// set what flags we want to enable for the transaction;
let flags = TransFlag::DB_ONLY | TransFlag::NO_DEPS;
// initialise the transaction
handle.trans_init(flags).unwrap();
// add the packages we want to install
// we could also remove packages with .trans_remove_pkg
handle.trans_add_pkg(pkg).unwrap();
// do a full sysupgrade
handle.sync_sysupgrade(false).unwrap();
// prepare the transaction
handle.trans_prepare().unwrap();
// fetch the list of packages we are going to install when we commit
let toinstall = handle.trans_add();
println!("{:#?}", toinstall);
// commit the transaction
// due to age the mirror now returns 404 for the package
assert!(handle.trans_commit().unwrap_err().error() == Error::Retrieve);
}