fix iterators with hack; fleshing out policy
This commit is contained in:
parent
d107ef373f
commit
67c2146b25
@ -6,17 +6,26 @@ use apt_pkg_native::Cache;
|
||||
|
||||
fn main() {
|
||||
let pkg = env::args().nth(1).expect("usage: first argument: package name");
|
||||
let arch = env::args().nth(2);
|
||||
|
||||
let mut cache = Cache::get_singleton();
|
||||
let found = cache.find_by_name(pkg.as_str());
|
||||
if found.is_empty() {
|
||||
let mut found = match arch {
|
||||
Some(arch) => cache.find_by_name_arch(pkg.as_str(), arch.as_str()),
|
||||
None => cache.find_by_name(pkg.as_str())
|
||||
};
|
||||
|
||||
if let Some(view) = found.next() {
|
||||
println!("{}:{}:", view.name(), view.arch());
|
||||
let installed_version = view.current_version().unwrap_or("(none)".to_string());
|
||||
println!(" Installed: {}", installed_version);
|
||||
println!(" Candidate: XXX");
|
||||
println!(" Version table:");
|
||||
for version in view.versions().map(simple::Version::from_iter) {
|
||||
println!(" {} {} XXX",
|
||||
if version.version == installed_version { "***" } else { " " },
|
||||
version.version);
|
||||
}
|
||||
} else {
|
||||
println!("unrecognised package: {}", pkg);
|
||||
return;
|
||||
}
|
||||
|
||||
println!("{}", found.pretty_print());
|
||||
|
||||
for version in found.versions().map(simple::Version::from_iter) {
|
||||
println!("{:?}", version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
18
src/sane.rs
18
src/sane.rs
@ -21,6 +21,7 @@ impl Cache {
|
||||
unsafe {
|
||||
PkgIterator {
|
||||
cache: self,
|
||||
first: true,
|
||||
ptr: raw::pkg_cache_pkg_iter(self.ptr)
|
||||
}
|
||||
}
|
||||
@ -32,6 +33,7 @@ impl Cache {
|
||||
let ptr = raw::pkg_cache_find_name(self.ptr, name.as_ptr());
|
||||
PkgIterator {
|
||||
cache: self,
|
||||
first: true,
|
||||
ptr,
|
||||
}
|
||||
}
|
||||
@ -44,6 +46,7 @@ impl Cache {
|
||||
let ptr = raw::pkg_cache_find_name_arch(self.ptr, name.as_ptr(), arch.as_ptr());
|
||||
PkgIterator {
|
||||
cache: self,
|
||||
first: true,
|
||||
ptr,
|
||||
}
|
||||
}
|
||||
@ -54,6 +57,7 @@ impl Cache {
|
||||
#[derive(Debug)]
|
||||
pub struct PkgIterator<'c> {
|
||||
cache: &'c Cache,
|
||||
first: bool,
|
||||
ptr: raw::PPkgIterator
|
||||
}
|
||||
|
||||
@ -75,7 +79,11 @@ impl<'c> PkgIterator<'c> {
|
||||
return None;
|
||||
}
|
||||
|
||||
raw::pkg_iter_next(self.ptr);
|
||||
if !self.first {
|
||||
raw::pkg_iter_next(self.ptr);
|
||||
}
|
||||
|
||||
self.first = false;
|
||||
|
||||
// we don't want to observe the end marker
|
||||
if self.is_empty() {
|
||||
@ -146,6 +154,7 @@ impl<'c> PkgIterator<'c> {
|
||||
pub fn versions(&self) -> VerIterator {
|
||||
VerIterator {
|
||||
cache: self.cache,
|
||||
first: true,
|
||||
ptr: unsafe { raw::pkg_iter_ver_iter(self.ptr) },
|
||||
}
|
||||
}
|
||||
@ -169,6 +178,7 @@ where F: FnMut(&PkgIterator) -> B {
|
||||
|
||||
pub struct VerIterator<'c> {
|
||||
cache: &'c Cache,
|
||||
first: bool,
|
||||
ptr: raw::PVerIterator,
|
||||
}
|
||||
|
||||
@ -188,7 +198,11 @@ impl<'c> VerIterator<'c> {
|
||||
return None;
|
||||
}
|
||||
|
||||
raw::ver_iter_next(self.ptr);
|
||||
if !self.first {
|
||||
raw::ver_iter_next(self.ptr);
|
||||
}
|
||||
|
||||
self.first = false;
|
||||
|
||||
// we don't want to observe the end marker
|
||||
if self.is_empty() {
|
||||
|
@ -17,11 +17,11 @@ impl BinaryPackage {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Version {
|
||||
version: String,
|
||||
arch: String,
|
||||
section: String,
|
||||
source_package: String,
|
||||
source_version: String,
|
||||
pub version: String,
|
||||
pub arch: String,
|
||||
pub section: String,
|
||||
pub source_package: String,
|
||||
pub source_version: String,
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user