diff options
author | Kornel <kornel@geekhood.net> | 2020-04-10 15:51:12 +0100 |
---|---|---|
committer | Kornel <kornel@geekhood.net> | 2020-04-10 15:51:12 +0100 |
commit | 97291a50844bd554738fd442b26f1de1d10863b4 (patch) | |
tree | 96807140fa1eff5f917b9d1227f19ed76a046802 | |
parent | ed76ea286ff2f5413cc4c5ca4ab3facb04bb9df9 (diff) |
More invalid names
-rw-r--r-- | crate_db/src/lib_crate_db.rs | 18 | ||||
m--------- | data/index | 0 |
2 files changed, 11 insertions, 7 deletions
diff --git a/crate_db/src/lib_crate_db.rs b/crate_db/src/lib_crate_db.rs index 78b10cd..e36a2d2 100644 --- a/crate_db/src/lib_crate_db.rs +++ b/crate_db/src/lib_crate_db.rs @@ -508,7 +508,7 @@ impl CrateDb { ")?; let q = q.query_map(&[&repo.canonical_git_url()], |r| { let s = r.get_raw(0).as_str()?; - Ok(Origin::from_crates_io_name(s)) + crates_io_name(s) })?.filter_map(|r| r.ok()); Ok(q.collect()) }).await @@ -535,7 +535,7 @@ impl CrateDb { loop { child_path = child_path.rsplitn(2, '/').nth(1).unwrap_or(""); if let Some(child) = paths.get(child_path) { - return Ok(Some(Origin::from_crates_io_name(child))); + return Ok(Origin::try_from_crates_io_name(child)); } if child_path.is_empty() { // in these paths "" is the root @@ -557,9 +557,9 @@ impl CrateDb { } Ok(if let Some(child) = repo.repo_name().and_then(|n| paths.get(n).or_else(|| paths.get(unprefix(n)))) { - Some(Origin::from_crates_io_name(child)) + Origin::try_from_crates_io_name(child) } else if let Some(child) = repo.owner_name().and_then(|n| paths.get(n).or_else(|| paths.get(unprefix(n)))) { - Some(Origin::from_crates_io_name(child)) + Origin::try_from_crates_io_name(child) } else { None }) @@ -802,7 +802,7 @@ impl CrateDb { "#)?; let res = query.query_map(&[&crate_name], |row| { let s = row.get_raw(1).as_str()?; - Ok(Origin::from_crates_io_name(s)) + crates_io_name(s) }).context("replacement_crates")?; Ok(res.collect::<std::result::Result<_,_>>()?) }).await @@ -913,8 +913,7 @@ impl CrateDb { let q = query.query_map(NO_PARAMS, |row| { let s = row.get_raw(0).as_str()?; let weight = row.get(1)?; - Ok((Origin::try_from_crates_io_name(s) - .ok_or_else(|| rusqlite::Error::ToSqlConversionFailure(format!("bad name in removals{}", s).into()))?, weight)) + Ok((crates_io_name(s)?, weight)) })?; let q = q.filter_map(|r| r.ok()); Ok(q.collect()) @@ -1159,6 +1158,11 @@ impl KeywordInsert { } } +fn crates_io_name(name: &str) -> std::result::Result<Origin, rusqlite::Error> { + Ok(Origin::try_from_crates_io_name(name) + .ok_or_else(|| rusqlite::Error::ToSqlConversionFailure(format!("bad name {}", name).into()))?) +} + #[derive(Debug)] pub struct CrateOwnerRow { pub origin: Origin, diff --git a/data/index b/data/index -Subproject 3cf42c0adff44e89d1860c2c1e3aaed01893c8e +Subproject 3f05fba118d259d3360a6aa636270d0d297dc71 |