Skip to content

Commit 21eddca

Browse files
committed
Merge remote-tracking branch 'upstream/master' into multi-token
2 parents fbbf538 + 9172aa4 commit 21eddca

File tree

18 files changed

+265
-116
lines changed

18 files changed

+265
-116
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE versions DROP COLUMN license;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE versions ADD COLUMN license VARCHAR;

src/bin/populate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ fn update(tx: &postgres::transaction::Transaction) -> postgres::Result<()> {
4040
dls += rng.gen_range(-100, 100);
4141
tx.execute(
4242
"INSERT INTO version_downloads \
43-
(version_id, downloads, date) \
44-
VALUES ($1, $2, $3)",
43+
(version_id, downloads, date) \
44+
VALUES ($1, $2, $3)",
4545
&[&id, &dls, &moment],
4646
)?;
4747
}

src/bin/update-licenses.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//! Updates all of the licenses from the existing crates into each of their
2+
//! already existing versions.
3+
4+
//
5+
// Usage:
6+
// cargo run --bin update-licenses
7+
8+
extern crate cargo_registry;
9+
extern crate postgres;
10+
11+
use std::io::prelude::*;
12+
13+
fn main() {
14+
let conn = cargo_registry::db::connect_now();
15+
{
16+
let tx = conn.transaction().unwrap();
17+
transfer(&tx);
18+
tx.set_commit();
19+
tx.finish().unwrap();
20+
}
21+
}
22+
23+
fn transfer(tx: &postgres::transaction::Transaction) {
24+
let stmt = tx.prepare("SELECT id, name, license FROM crates").unwrap();
25+
let rows = stmt.query(&[]).unwrap();
26+
27+
for row in rows.iter() {
28+
let id: i32 = row.get("id");
29+
let name: String = row.get("name");
30+
let license: Option<String> = row.get("license");
31+
32+
if let Some(license) = license {
33+
println!(
34+
"Setting the license for all versions of {} to {}.",
35+
name,
36+
license
37+
);
38+
39+
let num_updated = tx.execute(
40+
"UPDATE versions SET license = $1 WHERE crate_id = $2",
41+
&[&license, &id],
42+
).unwrap();
43+
assert!(num_updated > 0);
44+
} else {
45+
println!(
46+
"Ignoring crate `{}` because it doesn't have a license.",
47+
name
48+
);
49+
}
50+
}
51+
52+
get_confirm("Finish committing?");
53+
}
54+
55+
fn get_confirm(msg: &str) {
56+
print!("{} [y/N]: ", msg);
57+
std::io::stdout().flush().unwrap();
58+
59+
let mut line = String::new();
60+
std::io::stdin().read_line(&mut line).unwrap();
61+
62+
if !line.starts_with("y") {
63+
std::process::exit(0);
64+
}
65+
}

src/categories.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ pub fn sync() -> CargoResult<()> {
101101
for category in &categories {
102102
tx.execute(
103103
"\
104-
INSERT INTO categories (slug, category, description) \
105-
VALUES (LOWER($1), $2, $3) \
106-
ON CONFLICT (slug) DO UPDATE \
107-
SET category = EXCLUDED.category, \
108-
description = EXCLUDED.description;",
104+
INSERT INTO categories (slug, category, description) \
105+
VALUES (LOWER($1), $2, $3) \
106+
ON CONFLICT (slug) DO UPDATE \
107+
SET category = EXCLUDED.category, \
108+
description = EXCLUDED.description;",
109109
&[&category.slug, &category.name, &category.description],
110110
)?;
111111
}
@@ -119,8 +119,8 @@ pub fn sync() -> CargoResult<()> {
119119
tx.execute(
120120
&format!(
121121
"\
122-
DELETE FROM categories \
123-
WHERE slug NOT IN ({});",
122+
DELETE FROM categories \
123+
WHERE slug NOT IN ({});",
124124
in_clause
125125
),
126126
&[],

src/category.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Category {
6060
pub fn find_by_category(conn: &GenericConnection, name: &str) -> CargoResult<Category> {
6161
let stmt = conn.prepare(
6262
"SELECT * FROM categories \
63-
WHERE category = $1",
63+
WHERE category = $1",
6464
)?;
6565
let rows = stmt.query(&[&name])?;
6666
rows.iter().next().chain_error(|| NotFound).map(|row| {
@@ -71,7 +71,7 @@ impl Category {
7171
pub fn find_by_slug(conn: &GenericConnection, slug: &str) -> CargoResult<Category> {
7272
let stmt = conn.prepare(
7373
"SELECT * FROM categories \
74-
WHERE slug = LOWER($1)",
74+
WHERE slug = LOWER($1)",
7575
)?;
7676
let rows = stmt.query(&[&slug])?;
7777
rows.iter().next().chain_error(|| NotFound).map(|row| {
@@ -168,8 +168,8 @@ impl Category {
168168
if !to_rm.is_empty() {
169169
conn.execute(
170170
"DELETE FROM crates_categories \
171-
WHERE category_id = ANY($1) \
172-
AND crate_id = $2",
171+
WHERE category_id = ANY($1) \
172+
AND crate_id = $2",
173173
&[&to_rm, &krate.id],
174174
)?;
175175
}
@@ -183,7 +183,7 @@ impl Category {
183183
conn.execute(
184184
&format!(
185185
"INSERT INTO crates_categories \
186-
(crate_id, category_id) VALUES {}",
186+
(crate_id, category_id) VALUES {}",
187187
insert
188188
),
189189
&[],
@@ -196,9 +196,9 @@ impl Category {
196196
pub fn count_toplevel(conn: &GenericConnection) -> CargoResult<i64> {
197197
let sql = format!(
198198
"\
199-
SELECT COUNT(*) \
200-
FROM {} \
201-
WHERE category NOT LIKE '%::%'",
199+
SELECT COUNT(*) \
200+
FROM {} \
201+
WHERE category NOT LIKE '%::%'",
202202
Model::table_name(None::<Self>)
203203
);
204204
let stmt = conn.prepare(&sql)?;
@@ -272,16 +272,16 @@ impl Category {
272272
pub fn subcategories(&self, conn: &GenericConnection) -> CargoResult<Vec<Category>> {
273273
let stmt = conn.prepare(
274274
"\
275-
SELECT c.id, c.category, c.slug, c.description, c.created_at, \
276-
COALESCE (( \
277-
SELECT sum(c2.crates_cnt)::int \
278-
FROM categories as c2 \
279-
WHERE c2.slug = c.slug \
280-
OR c2.slug LIKE c.slug || '::%' \
281-
), 0) as crates_cnt \
282-
FROM categories as c \
283-
WHERE c.category ILIKE $1 || '::%' \
284-
AND c.category NOT ILIKE $1 || '::%::%'",
275+
SELECT c.id, c.category, c.slug, c.description, c.created_at, \
276+
COALESCE (( \
277+
SELECT sum(c2.crates_cnt)::int \
278+
FROM categories as c2 \
279+
WHERE c2.slug = c.slug \
280+
OR c2.slug LIKE c.slug || '::%' \
281+
), 0) as crates_cnt \
282+
FROM categories as c \
283+
WHERE c.category ILIKE $1 || '::%' \
284+
AND c.category NOT ILIKE $1 || '::%::%'",
285285
)?;
286286

287287
let rows = stmt.query(&[&self.category])?;
@@ -391,7 +391,7 @@ pub fn slugs(req: &mut Request) -> CargoResult<Response> {
391391
let conn = req.tx()?;
392392
let stmt = conn.prepare(
393393
"SELECT slug FROM categories \
394-
ORDER BY slug",
394+
ORDER BY slug",
395395
)?;
396396
let rows = stmt.query(&[])?;
397397

src/dependency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ pub fn add_dependencies(
149149
if dep.version_req == semver::VersionReq::parse("*").unwrap() {
150150
return Err(human(
151151
"wildcard (`*`) dependency constraints are not allowed \
152-
on crates.io. See http://doc.crates.io/faq.html#can-\
153-
libraries-use--as-a-version-for-their-dependencies for more \
154-
information",
152+
on crates.io. See http://doc.crates.io/faq.html#can-\
153+
libraries-use--as-a-version-for-their-dependencies for more \
154+
information",
155155
));
156156
}
157157
let features: Vec<_> = dep.features.iter().map(|s| &**s).collect();

src/http.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ pub fn parse_github_response<T: Decodable>(mut resp: Easy, data: &[u8]) -> Cargo
4949
403 => {
5050
return Err(human(
5151
"It looks like you don't have permission \
52-
to query a necessary property from Github \
53-
to complete this request. \
54-
You may need to re-authenticate on \
55-
crates.io to grant permission to read \
56-
github org memberships. Just go to \
57-
https://crates.io/login",
52+
to query a necessary property from Github \
53+
to complete this request. \
54+
You may need to re-authenticate on \
55+
crates.io to grant permission to read \
56+
github org memberships. Just go to \
57+
https://crates.io/login",
5858
));
5959
}
6060
n => {
6161
let resp = String::from_utf8_lossy(data);
6262
return Err(internal(&format_args!(
6363
"didn't get a 200 result from \
64-
github, got {} with: {}",
64+
github, got {} with: {}",
6565
n,
6666
resp
6767
)));

0 commit comments

Comments
 (0)