Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
511 changes: 305 additions & 206 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ s3 = { path = "src/s3" }
migrate = { path = "src/migrate" }
rand = "0.3"
time = "0.1"
git2 = "0.4"
git2 = "0.5"
flate2 = "0.2"
semver = "0.2"
url = "0.5.0"
postgres = { version = "0.11", features = ["time"] }
r2d2 = "0.6.0"
r2d2_postgres = "0.10"
semver = "0.5"
url = "1.2.1"
postgres = { version = "0.12", features = ["with-time"] }
r2d2 = "0.7.0"
r2d2_postgres = "0.11"
openssl = "0.7"
curl = "0.2"
oauth2 = "0.1"
Expand All @@ -36,20 +36,20 @@ rustc-serialize = "0.3"
license-exprs = "^1.3"
dotenv = "0.8.0"

conduit = "0.7"
conduit-conditional-get = "0.7"
conduit-cookie = "0.7"
conduit-json-parser = "0.7"
conduit-log-requests = "0.7"
conduit-middleware = "0.7"
conduit-router = "0.7"
conduit-static = "0.7"
conduit-git-http-backend = "0.7"
civet = "0.8"
conduit = "0.8"
conduit-conditional-get = "0.8"
conduit-cookie = "0.8"
conduit-json-parser = "0.8"
conduit-log-requests = "0.8"
conduit-middleware = "0.8"
conduit-router = "0.8"
conduit-static = "0.8"
conduit-git-http-backend = "0.8"
civet = "0.9"


[dev-dependencies]
conduit-test = "0.7"
conduit-test = "0.8"
bufstream = "0.1"

[features]
Expand Down
4 changes: 2 additions & 2 deletions src/bin/delete-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use cargo_registry::{Crate, env};
#[allow(dead_code)]
fn main() {
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
postgres::SslMode::None).unwrap();
postgres::TlsMode::None).unwrap();
{
let tx = conn.transaction().unwrap();
delete(&tx);
Expand All @@ -30,7 +30,7 @@ fn main() {
}
}

fn delete(tx: &postgres::Transaction) {
fn delete(tx: &postgres::transaction::Transaction) {
let name = match env::args().nth(1) {
None => { println!("needs a crate-name argument"); return }
Some(s) => s,
Expand Down
4 changes: 2 additions & 2 deletions src/bin/delete-version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use cargo_registry::{Crate, Version, env};
#[allow(dead_code)]
fn main() {
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
postgres::SslMode::None).unwrap();
postgres::TlsMode::None).unwrap();
{
let tx = conn.transaction().unwrap();
delete(&tx);
Expand All @@ -30,7 +30,7 @@ fn main() {
}
}

fn delete(tx: &postgres::Transaction) {
fn delete(tx: &postgres::transaction::Transaction) {
let name = match env::args().nth(1) {
None => { println!("needs a crate-name argument"); return }
Some(s) => s,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/fill-in-user-id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct GithubUser {
id: i32,
}

fn update(app: &App, tx: &postgres::Transaction) {
fn update(app: &App, tx: &postgres::transaction::Transaction) {
let mut rows = Vec::new();
let query = "SELECT id, gh_login, gh_access_token, gh_avatar FROM users \
WHERE gh_id IS NULL";
Expand Down
8 changes: 4 additions & 4 deletions src/bin/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cargo_registry::model::Model;
#[allow(dead_code)]
fn main() {
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
postgres::SslMode::None).unwrap();
postgres::TlsMode::None).unwrap();
let migrations = migrations();

let arg = env::args().nth(1);
Expand All @@ -26,7 +26,7 @@ fn main() {
}
}

fn apply(tx: postgres::Transaction,
fn apply(tx: postgres::transaction::Transaction,
migrations: Vec<Migration>) -> postgres::Result<()> {
let mut mgr = try!(migrate::Manager::new(tx));
for m in migrations.into_iter() {
Expand All @@ -36,7 +36,7 @@ fn apply(tx: postgres::Transaction,
mgr.finish()
}

fn rollback(tx: postgres::Transaction,
fn rollback(tx: postgres::transaction::Transaction,
migrations: Vec<Migration>) -> postgres::Result<()> {
let mut mgr = try!(migrate::Manager::new(tx));
for m in migrations.into_iter().rev() {
Expand Down Expand Up @@ -809,7 +809,7 @@ fn migrations() -> Vec<Migration> {
}

// DO NOT UPDATE OR USE FOR NEW MIGRATIONS
fn fix_duplicate_crate_owners(tx: &postgres::Transaction) -> postgres::Result<()> {
fn fix_duplicate_crate_owners(tx: &postgres::transaction::Transaction) -> postgres::Result<()> {
let v: Vec<(i32, i32)> = {
let stmt = try!(tx.prepare("SELECT user_id, crate_id
FROM crate_owners
Expand Down
4 changes: 2 additions & 2 deletions src/bin/populate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use cargo_registry::env;
#[allow(dead_code)]
fn main() {
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
postgres::SslMode::None).unwrap();
postgres::TlsMode::None).unwrap();
{
let tx = conn.transaction().unwrap();
update(&tx).unwrap();
Expand All @@ -29,7 +29,7 @@ fn main() {
}
}

fn update(tx: &postgres::Transaction) -> postgres::Result<()> {
fn update(tx: &postgres::transaction::Transaction) -> postgres::Result<()> {
let ids = env::args().skip(1).filter_map(|arg| {
arg.parse::<i32>().ok()
});
Expand Down
4 changes: 2 additions & 2 deletions src/bin/transfer-crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use cargo_registry::Model;
#[allow(dead_code)]
fn main() {
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
postgres::SslMode::None).unwrap();
postgres::TlsMode::None).unwrap();
{
let tx = conn.transaction().unwrap();
transfer(&tx);
Expand All @@ -29,7 +29,7 @@ fn main() {
}
}

fn transfer(tx: &postgres::Transaction) {
fn transfer(tx: &postgres::transaction::Transaction) {
let from = match env::args().nth(1) {
None => { println!("needs a from-user argument"); return }
Some(s) => s,
Expand Down
10 changes: 5 additions & 5 deletions src/bin/update-downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
let sleep = env::args().nth(2).map(|s| s.parse().unwrap());
loop {
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
postgres::SslMode::None).unwrap();
postgres::TlsMode::None).unwrap();
update(&conn).unwrap();
drop(conn);
if daemon {
Expand Down Expand Up @@ -54,7 +54,7 @@ fn update(conn: &postgres::GenericConnection) -> postgres::Result<()> {
Ok(())
}

fn collect(tx: &postgres::Transaction,
fn collect(tx: &postgres::transaction::Transaction,
rows: &mut postgres::rows::Rows) -> postgres::Result<Option<i32>> {
use time::Duration;

Expand Down Expand Up @@ -145,15 +145,15 @@ mod test {

fn conn() -> postgres::Connection {
postgres::Connection::connect(&env("TEST_DATABASE_URL")[..],
postgres::SslMode::None).unwrap()
postgres::TlsMode::None).unwrap()
}

fn user(conn: &postgres::Transaction) -> User{
fn user(conn: &postgres::transaction::Transaction) -> User{
User::find_or_insert(conn, 2, "login", None, None, None,
"access_token", "api_token").unwrap()
}

fn crate_downloads(tx: &postgres::Transaction, id: i32, expected: usize) {
fn crate_downloads(tx: &postgres::transaction::Transaction, id: i32, expected: usize) {
let stmt = tx.prepare("SELECT * FROM crate_downloads
WHERE crate_id = $1").unwrap();
let dl: i32 = stmt.query(&[&id]).unwrap().iter()
Expand Down
21 changes: 11 additions & 10 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use pg;
use pg::GenericConnection;
use r2d2;
use r2d2_postgres;
use r2d2_postgres::postgres;
use r2d2_postgres::PostgresConnectionManager as PCM;
use r2d2_postgres::SslMode;
use r2d2_postgres::TlsMode;
use conduit::{Request, Response};
use conduit_middleware::Middleware;

Expand All @@ -19,8 +20,8 @@ pub type Pool = r2d2::Pool<PCM>;
pub type Config = r2d2::Config<pg::Connection, r2d2_postgres::Error>;
type PooledConnnection = r2d2::PooledConnection<PCM>;

pub fn pool(url: &str, config: r2d2::Config<pg::Connection, r2d2_postgres::Error>) -> Pool {
let mgr = PCM::new(url, SslMode::None).unwrap();
pub fn pool(url: &str, config: r2d2::Config<postgres::Connection, r2d2_postgres::Error>) -> Pool {
let mgr = PCM::new(url, TlsMode::None).unwrap();
r2d2::Pool::new(config, mgr).unwrap()
}

Expand All @@ -35,7 +36,7 @@ pub struct Transaction {
// into `PooledConnnection`, but this `Transaction` can be moved around in
// memory, so we need the borrow to be from a stable address. The `Box` will
// provide this stable address.
tx: LazyCell<pg::Transaction<'static>>,
tx: LazyCell<pg::transaction::Transaction<'static>>,
slot: LazyCell<Box<PooledConnnection>>,
commit: Cell<Option<bool>>,

Expand All @@ -55,14 +56,14 @@ impl Transaction {
}
}

pub fn conn(&self) -> CargoResult<&pg::Connection> {
pub fn conn(&self) -> CargoResult<&r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>> {
if !self.slot.filled() {
let conn = try!(self.app.database.get().map_err(|e| {
internal(format!("failed to get a database connection: {}", e))
}));
self.slot.fill(Box::new(conn));
}
Ok(&***self.slot.borrow().unwrap())
Ok(&**self.slot.borrow().unwrap())
}

fn tx<'a>(&'a self) -> CargoResult<&'a (GenericConnection + 'a)> {
Expand All @@ -74,12 +75,12 @@ impl Transaction {
if !self.tx.filled() {
let conn = try!(self.conn());
let t = try!(conn.transaction());
let t = mem::transmute::<_, pg::Transaction<'static>>(t);
let t = mem::transmute::<_, pg::transaction::Transaction<'static>>(t);
self.tx.fill(t);
}
}
let tx = self.tx.borrow();
let tx: &'a pg::Transaction<'static> = tx.unwrap();
let tx: &'a pg::transaction::Transaction<'static> = tx.unwrap();
Ok(tx)
}

Expand Down Expand Up @@ -121,7 +122,7 @@ pub trait RequestTransaction {
/// Return the lazily initialized postgres connection for this request.
///
/// The connection will live for the lifetime of the request.
fn db_conn(&self) -> CargoResult<&pg::Connection>;
fn db_conn(&self) -> CargoResult<&r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>>;

/// Return the lazily initialized postgres transaction for this request.
///
Expand All @@ -136,7 +137,7 @@ pub trait RequestTransaction {
}

impl<'a> RequestTransaction for Request + 'a {
fn db_conn(&self) -> CargoResult<&pg::Connection> {
fn db_conn(&self) -> CargoResult<&r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>> {
self.extensions().find::<Transaction>()
.expect("Transaction not present in request")
.conn()
Expand Down
3 changes: 1 addition & 2 deletions src/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use conduit::{Request, Response};
use conduit_router::RequestParams;
use pg::GenericConnection;
use pg::rows::Row;
use pg::types::Slice;

use {Model, Crate};
use db::RequestTransaction;
Expand Down Expand Up @@ -95,7 +94,7 @@ impl Keyword {
try!(conn.execute("DELETE FROM crates_keywords
WHERE keyword_id = ANY($1)
AND crate_id = $2",
&[&Slice(&to_rm), &krate.id]));
&[&to_rm, &krate.id]));
}

if to_add.len() > 0 {
Expand Down
19 changes: 8 additions & 11 deletions src/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use curl::http;
use license_exprs;
use pg::GenericConnection;
use pg::rows::Row;
use pg::types::{ToSql, Slice};
use pg::types::ToSql;
use pg;
use rustc_serialize::hex::ToHex;
use rustc_serialize::json;
use semver;
use time::{Timespec, Duration};
use url::{self, Url};
use url::Url;

use {Model, User, Keyword, Version};
use app::{App, RequestApp};
Expand Down Expand Up @@ -182,17 +182,14 @@ impl Crate {
let url = try!(Url::parse(url).map_err(|_| {
human(format!("`{}` is not a valid url: `{}`", field, url))
}));
match &url.scheme[..] {
match &url.scheme()[..] {
"http" | "https" => {}
s => return Err(human(format!("`{}` has an invalid url \
scheme: `{}`", field, s)))
}
match url.scheme_data {
url::SchemeData::Relative(..) => {}
url::SchemeData::NonRelative(..) => {
return Err(human(format!("`{}` must have relative scheme \
data: {}", field, url)))
}
if url.cannot_be_a_base() {
return Err(human(format!("`{}` must have relative scheme \
data: {}", field, url)))
}
Ok(())
}
Expand Down Expand Up @@ -908,7 +905,7 @@ pub fn downloads(req: &mut Request) -> CargoResult<Response> {
AND version_id = ANY($2)
ORDER BY date ASC"));
let mut downloads = Vec::new();
for row in try!(stmt.query(&[&cutoff_date, &Slice(&ids)])).iter() {
for row in try!(stmt.query(&[&cutoff_date, &ids])).iter() {
let download: VersionDownload = Model::from_row(&row);
downloads.push(download.encodable());
}
Expand All @@ -925,7 +922,7 @@ pub fn downloads(req: &mut Request) -> CargoResult<Response> {
GROUP BY DATE(version_downloads.date)
ORDER BY DATE(version_downloads.date) ASC"));
let mut extra = Vec::new();
for row in try!(stmt.query(&[&cutoff_date, &krate.id, &Slice(&ids)])).iter() {
for row in try!(stmt.query(&[&cutoff_date, &krate.id, &ids])).iter() {
extra.push(ExtraDownload {
downloads: row.get("downloads"),
date: row.get("date")
Expand Down
2 changes: 1 addition & 1 deletion src/migrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ name = "migrate"
path = "lib.rs"

[dependencies]
postgres = "0.11"
postgres = "0.12"
4 changes: 2 additions & 2 deletions src/migrate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate postgres;

use std::collections::HashSet;

use postgres::Transaction;
use postgres::transaction::Transaction;
use postgres::Result as PgResult;

struct A<'a, 'b: 'a> {
Expand Down Expand Up @@ -72,7 +72,7 @@ fn run(sql: String) -> Step {
}

impl<'a> Manager<'a> {
pub fn new(tx: postgres::Transaction) -> PgResult<Manager> {
pub fn new(tx: Transaction) -> PgResult<Manager> {
let mut mgr = Manager { tx: tx, versions: HashSet::new() };
try!(mgr.load());
Ok(mgr)
Expand Down
Loading