indexer: Rust crate updates
This commit is contained in:
parent
1923b9901d
commit
d720441fb4
8 changed files with 140 additions and 126 deletions
|
|
@ -32,9 +32,9 @@ pub fn parse_path(path: &str) -> Option<(&str, &str, &str)> {
|
|||
}
|
||||
|
||||
let cap = match RE.captures(path) { Some(x) => x, None => return None };
|
||||
let locale = cap.at(1).unwrap_or("");
|
||||
let name = cap.at(2).unwrap();
|
||||
let section = cap.at(3).unwrap();
|
||||
let locale = cap.get(1).map(|e| e.as_str()).unwrap_or("");
|
||||
let name = cap.get(2).unwrap().as_str();
|
||||
let section = cap.get(3).unwrap().as_str();
|
||||
|
||||
// Not everything matching the regex is necessarily a man page, exclude some special cases.
|
||||
match (name, section, locale) {
|
||||
|
|
@ -105,7 +105,7 @@ fn codec_from_tag(data: &Vec<u8>) -> Option<EncodingRef> {
|
|||
static ref TAG: bytes::Regex = bytes::Regex::new(r"-\*-.*coding:\s*(?u:([^\s;]+)).*-\*").unwrap();
|
||||
}
|
||||
let cap = match TAG.captures(&data) { Some(x) => x, None => return None };
|
||||
let tag = str::from_utf8(cap.at(1).unwrap()).unwrap().to_lowercase();
|
||||
let tag = str::from_utf8(&cap[1]).unwrap().to_lowercase();
|
||||
|
||||
match &tag[..] {
|
||||
// Deny some common UTF-8-compatible encodings. These tags are irrelevant because we're
|
||||
|
|
@ -143,9 +143,9 @@ fn codec_from_path(path: &str) -> Option<EncodingRef> {
|
|||
}
|
||||
|
||||
let cap = match RE.captures(&locale) { Some(x) => x, None => return None };
|
||||
let lang = cap.at(1).unwrap();
|
||||
let seclang = cap.at(2);
|
||||
let enc = cap.at(3);
|
||||
let lang = &cap[1];
|
||||
let seclang = cap.get(2).map(|e| e.as_str());
|
||||
let enc = cap.get(3).map(|e| e.as_str());
|
||||
|
||||
// Try to do something with the encoding tag
|
||||
match (lang, enc) {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ impl<'a> Path<'a> {
|
|||
// parsable file list, some servers have issues with generating a list of a large directory)
|
||||
pub fn dirlist(&self) -> Result<Vec<(String,bool)>> {
|
||||
lazy_static!(
|
||||
static ref RE: Regex = Regex::new("(?i:<a +href *= *\"([^?/\"]+)(/?)\">)").unwrap();
|
||||
static ref RE: Regex = Regex::new("(?i:<a +href *= *\"([^?/\"]+)(/)?\">)").unwrap();
|
||||
);
|
||||
let rd = self.open()?;
|
||||
let brd = BufReader::new(rd);
|
||||
|
|
@ -118,12 +118,12 @@ impl<'a> Path<'a> {
|
|||
}
|
||||
|
||||
if let Some(cap) = first {
|
||||
let name = cap.at(1).unwrap();
|
||||
let name = &cap[1];
|
||||
if name == b".." || name.starts_with(b"/") {
|
||||
continue;
|
||||
}
|
||||
if let Ok(name) = percent_decode(name).decode_utf8() {
|
||||
let isdir = cap.at(2) == Some(b"/");
|
||||
let isdir = cap.get(2).is_some();
|
||||
res.push((name.to_string(), isdir));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ fn read_desc(rd: &mut archive::ArchiveEntry) -> Result<Option<Meta>> {
|
|||
let mut arch = None;
|
||||
|
||||
for kv in RE.captures_iter(&data) {
|
||||
let key = kv.at(1).unwrap();
|
||||
let val = kv.at(2).unwrap();
|
||||
let key = &kv[1];
|
||||
let val = kv.get(2).unwrap().as_str();
|
||||
trace!("{}: {} = {}", path, key, val);
|
||||
match key {
|
||||
"FILENAME" => filename = Some(val),
|
||||
|
|
|
|||
|
|
@ -124,9 +124,9 @@ pub fn sync(pg: &postgres::GenericConnection, sys: i32, mirror: &str, contents:
|
|||
pkg = Pkg::default();
|
||||
}
|
||||
if let Some(cap) = kv.captures(&line) {
|
||||
let val = str::from_utf8(cap.at(2).unwrap()).unwrap();
|
||||
let val = str::from_utf8(&cap[2]).unwrap();
|
||||
// Use case-insensitive matching, older package archives used lowercase keys
|
||||
match str::from_utf8(cap.at(1).unwrap()).unwrap().to_lowercase().as_ref() {
|
||||
match str::from_utf8(&cap[1]).unwrap().to_lowercase().as_ref() {
|
||||
"package" => pkg.name = Some(val.to_string()),
|
||||
"section" => pkg.section = Some(val.to_string()),
|
||||
"version" => pkg.version = Some(val.to_string()),
|
||||
|
|
|
|||
|
|
@ -103,9 +103,9 @@ fn splitver(n: &str) -> Option<(&str, &str)> {
|
|||
static ref RE2: Regex = Regex::new("^(.+)-([^-]+)$").unwrap();
|
||||
);
|
||||
if let Some(cap) = RE1.captures(n) {
|
||||
Some((cap.at(1).unwrap(), cap.at(2).unwrap()))
|
||||
Some((cap.get(1).unwrap().as_str(), cap.get(2).unwrap().as_str()))
|
||||
} else if let Some(cap) = RE2.captures(n) {
|
||||
Some((cap.at(1).unwrap(), cap.at(2).unwrap()))
|
||||
Some((cap.get(1).unwrap().as_str(), cap.get(2).unwrap().as_str()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ pub fn sync(pg: &postgres::GenericConnection, sys: i32, mirror: &str) -> Result<
|
|||
|
||||
for line in brd.split(b'\n') {
|
||||
let line = line?;
|
||||
let name = match RE_NAME.captures(&line) { None => continue, Some(c) => str::from_utf8(c.at(1).unwrap()).unwrap() };
|
||||
let ver = match RE_VER .captures(&line) { None => continue, Some(c) => str::from_utf8(c.at(1).unwrap()).unwrap() };
|
||||
let cat = match RE_CAT .captures(&line) { None => continue, Some(c) => str::from_utf8(c.at(1).unwrap()).unwrap() };
|
||||
let path = match RE_PATH.captures(&line) { None => continue, Some(c) => str::from_utf8(c.at(1).unwrap()).unwrap() };
|
||||
let arch = match RE_ARCH.captures(&line) { None => continue, Some(c) => str::from_utf8(c.at(1).unwrap()).unwrap() };
|
||||
let name = match RE_NAME.captures(&line) { None => continue, Some(c) => str::from_utf8(c.get(1).unwrap().as_bytes()).unwrap() };
|
||||
let ver = match RE_VER .captures(&line) { None => continue, Some(c) => str::from_utf8(c.get(1).unwrap().as_bytes()).unwrap() };
|
||||
let cat = match RE_CAT .captures(&line) { None => continue, Some(c) => str::from_utf8(c.get(1).unwrap().as_bytes()).unwrap() };
|
||||
let path = match RE_PATH.captures(&line) { None => continue, Some(c) => str::from_utf8(c.get(1).unwrap().as_bytes()).unwrap() };
|
||||
let arch = match RE_ARCH.captures(&line) { None => continue, Some(c) => str::from_utf8(c.get(1).unwrap().as_bytes()).unwrap() };
|
||||
let uri = format!("{}{}", mirror, path);
|
||||
pkg::pkg(pg, pkg::PkgOpt{
|
||||
force: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue