indexer: Update crates to latest version

With the exception of Hyper, because the new tokio-based version is...
different.
This commit is contained in:
Yorhel 2018-03-25 10:36:26 +02:00
parent 8487d37aad
commit 2c7bf1507a
5 changed files with 801 additions and 295 deletions

960
indexer/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,17 +4,17 @@ version = "0.1.0"
authors = ["Yorhel <git@yorhel.nl>"] authors = ["Yorhel <git@yorhel.nl>"]
[dependencies] [dependencies]
regex = "0.2.1" regex = "0.2.10"
log = "0.3.6" log = "0.4.1"
env_logger = "0.4.0" env_logger = "0.5.6"
lazy_static = "0.2.1" lazy_static = "1.0.0"
libc = "0.2.17" libc = "0.2.39"
libarchive3-sys = "0.1.2" libarchive3-sys = "0.1.2"
encoding = { git = "https://github.com/lifthrasiir/rust-encoding", features = ["no-optimized-legacy-encoding"] } encoding = { git = "https://github.com/lifthrasiir/rust-encoding", features = ["no-optimized-legacy-encoding"] }
ring = "0.6.2" ring = "0.12.1"
postgres = "0.13.5" postgres = "0.15.2"
clap = "2.20.0" clap = "2.31.2"
hyper = { version = "0.10.0", default-features = false } hyper = { version = "0.10.13", default-features = false } # TODO: Update?
url = "1.2.3" url = "1.7.0"
chrono = "0.2.25" chrono = "0.4.0"
quick-xml = "0.5.0" quick-xml = "0.12.1"

View file

@ -93,15 +93,15 @@ fn main() {
unsafe { pkg::DRY_RUN = arg.is_present("dry") }; unsafe { pkg::DRY_RUN = arg.is_present("dry") };
let verbose = arg.occurrences_of("v"); let verbose = arg.occurrences_of("v");
env_logger::LogBuilder::new() env_logger::Builder::new()
.filter(Some("indexer"), match verbose { .filter(Some("indexer"), match verbose {
0 => log::LogLevelFilter::Warn, 0 => log::LevelFilter::Warn,
1 => log::LogLevelFilter::Info, 1 => log::LevelFilter::Info,
2 => log::LogLevelFilter::Debug, 2 => log::LevelFilter::Debug,
_ => log::LogLevelFilter::Trace, _ => log::LevelFilter::Trace,
}) })
.filter(Some("postgres"), if verbose >= 4 { log::LogLevelFilter::Trace } else { log::LogLevelFilter::Info }) .filter(Some("postgres"), if verbose >= 4 { log::LevelFilter::Trace } else { log::LevelFilter::Info })
.init().unwrap(); .init();
if let Err(e) = open::clear_cache() { if let Err(e) = open::clear_cache() {
error!("Error clearing cache: {}", e); error!("Error clearing cache: {}", e);

View file

@ -1,5 +1,4 @@
use std::collections::HashSet; use std::collections::HashSet;
use std::ascii::AsciiExt;
use std::io::Result; use std::io::Result;
use regex::Regex; use regex::Regex;
use postgres; use postgres;

View file

@ -2,9 +2,11 @@ use std::collections::HashSet;
use std::io::BufReader; use std::io::BufReader;
use std::str::FromStr; use std::str::FromStr;
use std::error::Error; use std::error::Error;
use std::fmt;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use postgres; use postgres;
use quick_xml as xml; use quick_xml as xml;
use quick_xml::events::Event;
use archive; use archive;
use open; use open;
@ -12,14 +14,29 @@ use pkg;
use man; use man;
fn xml_getattr(e: &xml::Element, attr: &str) -> Result<String,Box<Error>> { // Ugh, quick-xml's Error type does not implement Error.
for kv in e.unescaped_attributes() { #[derive(Debug)]
let (key, val) = kv.map_err(|(e,_)| e)?; struct XmlError(String);
if key == attr.as_bytes() { impl fmt::Display for XmlError {
return Ok(String::from_utf8(val.into_owned())?); fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) }
}
impl Error for XmlError {
fn description(&self) -> &str { self.0.as_ref() }
}
fn to_err(e: xml::Error) -> XmlError {
XmlError(format!("{}", e))
}
fn xml_getattr(e: &xml::events::BytesStart, attr: &str) -> Result<String,Box<Error>> {
for kv in e.attributes().with_checks(false) {
let kv = kv.map_err(to_err)?;
if kv.key == attr.as_bytes() {
return Ok(String::from_utf8(kv.value.into_owned())?);
} }
} }
Err(Box::new(xml::error::Error::EOL)) Err(Box::new(XmlError(format!("Attribute '{}' not found", attr))))
} }
@ -41,23 +58,28 @@ fn readpkgs<F>(url: String, mut cb: F) -> Result<(),Box<Error>>
{ {
debug!("Reading {}", url); debug!("Reading {}", url);
let mut fd = open::Path{path: &url, cache: true, canbelocal: false}.open()?; let mut fd = open::Path{path: &url, cache: true, canbelocal: false}.open()?;
let xml = xml::XmlReader::from_reader( let mut xml = xml::Reader::from_reader(
BufReader::new( BufReader::new(
archive::Archive::open_raw(&mut fd)? archive::Archive::open_raw(&mut fd)?
) )
).trim_text(true); );
xml.trim_text(true);
let mut savestr = false; let mut savestr = false;
let mut saved = None; let mut saved = None;
let mut pkg = PkgInfo::default(); let mut pkg = PkgInfo::default();
let mut buf = Vec::new();
let arch_src = Some("src".to_string()); let arch_src = Some("src".to_string());
for event in xml { loop {
let event = event.map_err(|(e,_)| e)?; let event = xml.read_event(&mut buf);
let event = event.map_err(to_err)?;
match event { match event {
xml::Event::Start(ref e) => Event::Start(ref e) |
Event::Empty(ref e) =>
match e.name() { match e.name() {
b"name" | b"name" |
b"file" | b"file" |
@ -72,13 +94,13 @@ fn readpkgs<F>(url: String, mut cb: F) -> Result<(),Box<Error>>
_ => (), _ => (),
}, },
xml::Event::Text(e) => Event::Text(e) =>
if savestr { if savestr {
saved = Some(e.into_unescaped_string()?); saved = Some(e.unescape_and_decode(&xml).map_err(to_err)?);
savestr = false savestr = false
}, },
xml::Event::End(ref e) => { Event::End(ref e) => {
savestr = false; savestr = false;
match e.name() { match e.name() {
b"name" => pkg.name = Some(saved.take().unwrap()), b"name" => pkg.name = Some(saved.take().unwrap()),
@ -94,6 +116,7 @@ fn readpkgs<F>(url: String, mut cb: F) -> Result<(),Box<Error>>
}; };
}, },
Event::Eof => break,
_ => (), _ => (),
} }
} }
@ -105,35 +128,43 @@ fn readpkgs<F>(url: String, mut cb: F) -> Result<(),Box<Error>>
fn repomd(url: String) -> Result<(String,String),Box<Error>> { fn repomd(url: String) -> Result<(String,String),Box<Error>> {
debug!("Reading {}", url); debug!("Reading {}", url);
let mut fd = open::Path{path: &url, cache: true, canbelocal: false}.open()?; let mut fd = open::Path{path: &url, cache: true, canbelocal: false}.open()?;
let xml = xml::XmlReader::from_reader( let mut xml = xml::Reader::from_reader(
BufReader::new( BufReader::new(
archive::Archive::open_raw(&mut fd)? archive::Archive::open_raw(&mut fd)?
) )
).trim_text(true); );
xml.trim_text(true);
let mut primary = String::new(); let mut primary = String::new();
let mut filelists = String::new(); let mut filelists = String::new();
let mut datatype = 0; let mut datatype = 0;
let mut buf = Vec::new();
for event in xml { loop {
if let xml::Event::Start(ref e) = event.map_err(|(e,_)| e)? { let event = xml.read_event(&mut buf).map_err(to_err)?;
match e.name() { match event {
b"data" => Event::Start(ref e) |
datatype = match &xml_getattr(e, "type")? as &str { Event::Empty(ref e) => {
"primary" => 1, match e.name() {
"filelists" => 2, b"data" =>
_ => 0, datatype = match &xml_getattr(e, "type")? as &str {
}, "primary" => 1,
"filelists" => 2,
_ => 0,
},
b"location" => b"location" =>
match datatype { match datatype {
1 => primary = xml_getattr(e, "href")?, 1 => primary = xml_getattr(e, "href")?,
2 => filelists = xml_getattr(e, "href")?, 2 => filelists = xml_getattr(e, "href")?,
_ => (), _ => (),
}, },
_ => (), _ => (),
} }
},
Event::Eof => break,
_ => (),
} }
} }
Ok((primary, filelists)) Ok((primary, filelists))