Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Started working on having the ability to have a different license for each version of a crate. #787

Merged
merged 32 commits into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e3ee1eb
Add diesel migration to add 'license' column to 'versions' table.
baileyn Jun 11, 2017
9bb2387
Created update-licenses to update previous versions of crates to have…
baileyn Jun 12, 2017
847959a
Removed NewKrate taking a license file. Now, NewVersion will accept t…
baileyn Jun 14, 2017
965a340
Stopped EncodableCrate from returning a license, and instead made Enc…
baileyn Jun 14, 2017
68d829e
Updated the tests to pass.
baileyn Jun 14, 2017
38d1e01
Merge branch 'master' into licenses
baileyn Jun 14, 2017
3f859bf
Add diesel migration to add 'license' column to 'versions' table.
baileyn Jun 11, 2017
4e4531f
Created update-licenses to update previous versions of crates to have…
baileyn Jun 12, 2017
54bbee4
Removed NewKrate taking a license file. Now, NewVersion will accept t…
baileyn Jun 14, 2017
19366e8
Stopped EncodableCrate from returning a license, and instead made Enc…
baileyn Jun 14, 2017
c917ac4
Updated the tests to pass.
baileyn Jun 14, 2017
f937d09
Merge branch 'licenses' of github.com:baileyn/crates.io into licenses
baileyn Jun 14, 2017
6542f3c
Added VersionBuilder and converted tests to use it.
baileyn Jun 15, 2017
db1ab7e
Created a test to make sure license can change between versions.
baileyn Jun 15, 2017
7436b02
Add diesel migration to add 'license' column to 'versions' table.
baileyn Jun 11, 2017
4130c66
Created update-licenses to update previous versions of crates to have…
baileyn Jun 12, 2017
691b61b
Removed NewKrate taking a license file. Now, NewVersion will accept t…
baileyn Jun 14, 2017
d5f0bdb
Stopped EncodableCrate from returning a license, and instead made Enc…
baileyn Jun 14, 2017
1747eee
Updated the tests to pass.
baileyn Jun 14, 2017
98f5335
Removed NewKrate taking a license file. Now, NewVersion will accept t…
baileyn Jun 14, 2017
c404f14
Stopped EncodableCrate from returning a license, and instead made Enc…
baileyn Jun 14, 2017
4e8f84f
Updated the tests to pass.
baileyn Jun 14, 2017
a8b97d4
Added VersionBuilder and converted tests to use it.
baileyn Jun 15, 2017
8ed3be0
Created a test to make sure license can change between versions.
baileyn Jun 15, 2017
e7c07fa
Added the `license` fields back to the Crate/EncodableCrate so that t…
baileyn Jun 19, 2017
1961032
Merge branch 'licenses' of github.com:baileyn/crates.io into licenses
baileyn Jun 19, 2017
a1911e7
Added back the functionality for the Crate's holding their licensing …
baileyn Jun 19, 2017
1497b84
Stopped taking a reference of a reference.
baileyn Jun 19, 2017
1be72f9
Ran cargo fmt
baileyn Jun 19, 2017
8d8305d
Soooo I updated rustfmt to nightly and then ran it again.
baileyn Jun 19, 2017
41ae4c0
cargo fmt again
carols10cents Jun 21, 2017
a2c6644
Updated 'update-license' binary to handle if the crate doesn't curren…
baileyn Jun 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migrations/20170611165120_add_license_to_versions/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE versions DROP COLUMN license;
1 change: 1 addition & 0 deletions migrations/20170611165120_add_license_to_versions/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE versions ADD COLUMN license VARCHAR;
4 changes: 2 additions & 2 deletions src/bin/populate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn update(tx: &postgres::transaction::Transaction) -> postgres::Result<()> {
dls += rng.gen_range(-100, 100);
tx.execute(
"INSERT INTO version_downloads \
(version_id, downloads, date) \
VALUES ($1, $2, $3)",
(version_id, downloads, date) \
VALUES ($1, $2, $3)",
&[&id, &dls, &moment],
)?;
}
Expand Down
65 changes: 65 additions & 0 deletions src/bin/update-licenses.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Updates all of the licenses from the existing crates into each of their
//! already existing versions.

//
// Usage:
// cargo run --bin update-licenses

extern crate cargo_registry;
extern crate postgres;

use std::io::prelude::*;

fn main() {
let conn = cargo_registry::db::connect_now();
{
let tx = conn.transaction().unwrap();
transfer(&tx);
tx.set_commit();
tx.finish().unwrap();
}
}

fn transfer(tx: &postgres::transaction::Transaction) {
let stmt = tx.prepare("SELECT id, name, license FROM crates").unwrap();
let rows = stmt.query(&[]).unwrap();

for row in rows.iter() {
let id: i32 = row.get("id");
let name: String = row.get("name");
let license: Option<String> = row.get("license");

if let Some(license) = license {
println!(
"Setting the license for all versions of {} to {}.",
name,
license
);

let num_updated = tx.execute(
"UPDATE versions SET license = $1 WHERE crate_id = $2",
&[&license, &id],
).unwrap();
assert!(num_updated > 0);
} else {
println!(
"Ignoring crate `{}` because it doesn't have a license.",
name
);
}
}

get_confirm("Finish committing?");
}

fn get_confirm(msg: &str) {
print!("{} [y/N]: ", msg);
std::io::stdout().flush().unwrap();

let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();

if !line.starts_with("y") {
std::process::exit(0);
}
}
14 changes: 7 additions & 7 deletions src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ pub fn sync() -> CargoResult<()> {
for category in &categories {
tx.execute(
"\
INSERT INTO categories (slug, category, description) \
VALUES (LOWER($1), $2, $3) \
ON CONFLICT (slug) DO UPDATE \
SET category = EXCLUDED.category, \
description = EXCLUDED.description;",
INSERT INTO categories (slug, category, description) \
VALUES (LOWER($1), $2, $3) \
ON CONFLICT (slug) DO UPDATE \
SET category = EXCLUDED.category, \
description = EXCLUDED.description;",
&[&category.slug, &category.name, &category.description],
)?;
}
Expand All @@ -119,8 +119,8 @@ pub fn sync() -> CargoResult<()> {
tx.execute(
&format!(
"\
DELETE FROM categories \
WHERE slug NOT IN ({});",
DELETE FROM categories \
WHERE slug NOT IN ({});",
in_clause
),
&[],
Expand Down
38 changes: 19 additions & 19 deletions src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Category {
pub fn find_by_category(conn: &GenericConnection, name: &str) -> CargoResult<Category> {
let stmt = conn.prepare(
"SELECT * FROM categories \
WHERE category = $1",
WHERE category = $1",
)?;
let rows = stmt.query(&[&name])?;
rows.iter().next().chain_error(|| NotFound).map(|row| {
Expand All @@ -71,7 +71,7 @@ impl Category {
pub fn find_by_slug(conn: &GenericConnection, slug: &str) -> CargoResult<Category> {
let stmt = conn.prepare(
"SELECT * FROM categories \
WHERE slug = LOWER($1)",
WHERE slug = LOWER($1)",
)?;
let rows = stmt.query(&[&slug])?;
rows.iter().next().chain_error(|| NotFound).map(|row| {
Expand Down Expand Up @@ -168,8 +168,8 @@ impl Category {
if !to_rm.is_empty() {
conn.execute(
"DELETE FROM crates_categories \
WHERE category_id = ANY($1) \
AND crate_id = $2",
WHERE category_id = ANY($1) \
AND crate_id = $2",
&[&to_rm, &krate.id],
)?;
}
Expand All @@ -183,7 +183,7 @@ impl Category {
conn.execute(
&format!(
"INSERT INTO crates_categories \
(crate_id, category_id) VALUES {}",
(crate_id, category_id) VALUES {}",
insert
),
&[],
Expand All @@ -196,9 +196,9 @@ impl Category {
pub fn count_toplevel(conn: &GenericConnection) -> CargoResult<i64> {
let sql = format!(
"\
SELECT COUNT(*) \
FROM {} \
WHERE category NOT LIKE '%::%'",
SELECT COUNT(*) \
FROM {} \
WHERE category NOT LIKE '%::%'",
Model::table_name(None::<Self>)
);
let stmt = conn.prepare(&sql)?;
Expand Down Expand Up @@ -272,16 +272,16 @@ impl Category {
pub fn subcategories(&self, conn: &GenericConnection) -> CargoResult<Vec<Category>> {
let stmt = conn.prepare(
"\
SELECT c.id, c.category, c.slug, c.description, c.created_at, \
COALESCE (( \
SELECT sum(c2.crates_cnt)::int \
FROM categories as c2 \
WHERE c2.slug = c.slug \
OR c2.slug LIKE c.slug || '::%' \
), 0) as crates_cnt \
FROM categories as c \
WHERE c.category ILIKE $1 || '::%' \
AND c.category NOT ILIKE $1 || '::%::%'",
SELECT c.id, c.category, c.slug, c.description, c.created_at, \
COALESCE (( \
SELECT sum(c2.crates_cnt)::int \
FROM categories as c2 \
WHERE c2.slug = c.slug \
OR c2.slug LIKE c.slug || '::%' \
), 0) as crates_cnt \
FROM categories as c \
WHERE c.category ILIKE $1 || '::%' \
AND c.category NOT ILIKE $1 || '::%::%'",
)?;

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

Expand Down
6 changes: 3 additions & 3 deletions src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ pub fn add_dependencies(
if dep.version_req == semver::VersionReq::parse("*").unwrap() {
return Err(human(
"wildcard (`*`) dependency constraints are not allowed \
on crates.io. See http://doc.crates.io/faq.html#can-\
libraries-use--as-a-version-for-their-dependencies for more \
information",
on crates.io. See http://doc.crates.io/faq.html#can-\
libraries-use--as-a-version-for-their-dependencies for more \
information",
));
}
let features: Vec<_> = dep.features.iter().map(|s| &**s).collect();
Expand Down
14 changes: 7 additions & 7 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ pub fn parse_github_response<T: Decodable>(mut resp: Easy, data: &[u8]) -> Cargo
403 => {
return Err(human(
"It looks like you don't have permission \
to query a necessary property from Github \
to complete this request. \
You may need to re-authenticate on \
crates.io to grant permission to read \
github org memberships. Just go to \
https://crates.io/login",
to query a necessary property from Github \
to complete this request. \
You may need to re-authenticate on \
crates.io to grant permission to read \
github org memberships. Just go to \
https://crates.io/login",
));
}
n => {
let resp = String::from_utf8_lossy(data);
return Err(internal(&format_args!(
"didn't get a 200 result from \
github, got {} with: {}",
github, got {} with: {}",
n,
resp
)));
Expand Down
Loading