Skip to content

Commit 71b962a

Browse files
committed
Update to rust master
1 parent e888625 commit 71b962a

17 files changed

+108
-93
lines changed

Cargo.lock

Lines changed: 60 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ url = "0.2.0"
5050
postgres = { version = "0.8", features = ["time"] }
5151
r2d2 = "0.5.0"
5252
r2d2_postgres = "0.9"
53-
openssl = "0.5"
53+
openssl = "0.6"
5454
curl = "0.2"
5555
oauth2 = "0.1"
5656
log = "0.3"

RUSTVERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2015-03-26
1+
2015-04-08

src/bin/populate.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
// cargo run --bin populate version_id1 version_id2 ...
66

77
#![deny(warnings)]
8-
#![feature(std_misc)]
98

109
extern crate cargo_registry;
1110
extern crate postgres;
1211
extern crate time;
1312
extern crate rand;
1413

1514
use std::env;
16-
use std::time::Duration;
15+
use time::Duration;
1716
use rand::{StdRng, Rng};
1817

1918
fn main() {

src/bin/server.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![deny(warnings)]
2-
#![feature(convert)]
32

43
extern crate cargo_registry;
54
extern crate conduit_middleware;

src/bin/update-downloads.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![deny(warnings)]
2-
#![feature(std_misc, thread_sleep)]
32

43
extern crate cargo_registry;
54
extern crate postgres;
@@ -8,7 +7,7 @@ extern crate time;
87

98
use std::env;
109
use std::collections::HashMap;
11-
use std::time::Duration;
10+
use time::Duration;
1211

1312
use cargo_registry::{VersionDownload, Version, Model};
1413

@@ -18,14 +17,14 @@ static LIMIT: i64 = 1000;
1817
fn main() {
1918
let daemon = env::args().nth(1).as_ref().map(|s| &s[..])
2019
== Some("daemon");
21-
let sleep = env::args().nth(2).map(|s| s.parse::<i64>().unwrap());
20+
let sleep = env::args().nth(2).map(|s| s.parse::<u32>().unwrap());
2221
loop {
2322
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
2423
&postgres::SslMode::None).unwrap();
2524
update(&conn).unwrap();
2625
drop(conn);
2726
if daemon {
28-
std::thread::sleep(Duration::seconds(sleep.unwrap()));
27+
std::thread::sleep_ms(sleep.unwrap() * 1000);
2928
} else {
3029
break
3130
}

src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type PooledConnnection<'a> =
1818
r2d2::PooledConnection<'a, PostgresConnectionManager>;
1919

2020
pub fn pool(url: &str, config: r2d2::Config) -> Pool {
21-
let mgr = PostgresConnectionManager::new(url, pg::SslMode::None);
21+
let mgr = PostgresConnectionManager::new(url, pg::SslMode::None).unwrap();
2222
r2d2::Pool::new(config, mgr, Box::new(LoggingErrorHandler)).unwrap()
2323
}
2424

src/dependency.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::num::FromPrimitive;
2-
31
use semver;
42

53
use pg;
@@ -33,11 +31,15 @@ pub struct EncodableDependency {
3331
pub kind: Kind,
3432
}
3533

36-
#[derive(FromPrimitive, Copy, Clone)]
34+
#[derive(Copy, Clone)]
35+
// NB: this order is important, it must be retained! The database stores an
36+
// integer corresponding to each variant.
3737
pub enum Kind {
3838
Normal,
3939
Build,
4040
Dev,
41+
42+
// if you add a kind here, be sure to update `from_row` below.
4143
}
4244

4345
impl Dependency {
@@ -106,7 +108,12 @@ impl Model for Dependency {
106108
features: features.split(',').map(|s| s.to_string())
107109
.collect(),
108110
target: row.get("target"),
109-
kind: FromPrimitive::from_i32(kind.unwrap_or(0)).unwrap(),
111+
kind: match kind.unwrap_or(0) {
112+
0 => Kind::Normal,
113+
1 => Kind::Build,
114+
2 => Kind::Dev,
115+
n => panic!("unknown kind: {}", n),
116+
}
110117
}
111118
}
112119

src/git.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_serialize::json;
1010

1111
use app::App;
1212
use dependency::Kind;
13-
use util::{CargoResult, internal, ChainError};
13+
use util::{CargoResult, internal};
1414

1515
#[derive(RustcEncodable, RustcDecodable)]
1616
pub struct Crate {
@@ -34,7 +34,7 @@ pub struct Dependency {
3434
}
3535

3636
fn index_file(base: &Path, name: &str) -> PathBuf {
37-
let name = name.to_lowercase();
37+
let name = name.chars().flat_map(|c| c.to_lowercase()).collect::<String>();
3838
match name.len() {
3939
1 => base.join("1").join(&name),
4040
2 => base.join("2").join(&name),
@@ -141,9 +141,6 @@ fn commit_and_push<F>(repo: &git2::Repository, mut f: F) -> CargoResult<()>
141141

142142
match push.finish() {
143143
Ok(()) => {
144-
try!(push.statuses().chain_error(|| {
145-
internal("failed to update some remote refspecs")
146-
}));
147144
try!(push.update_tips(None, None));
148145
return Ok(())
149146
}

src/keyword.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl Keyword {
6363

6464
pub fn valid_name(name: &str) -> bool {
6565
if name.len() == 0 { return false }
66-
name.char_at(0).is_alphanumeric() &&
66+
name.chars().next().unwrap().is_alphanumeric() &&
6767
name.chars().all(|c| c.is_alphanumeric() || c == '_' || c == '-') &&
6868
name.chars().all(|c| c.is_ascii())
6969
}

src/krate.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::io;
66
use std::iter::repeat;
77
use std::mem;
88
use std::sync::Arc;
9-
use std::time::Duration;
109

1110
use conduit::{Request, Response};
1211
use conduit_router::RequestParams;
@@ -16,7 +15,7 @@ use pg;
1615
use rustc_serialize::hex::ToHex;
1716
use rustc_serialize::json;
1817
use semver;
19-
use time::Timespec;
18+
use time::{Timespec, Duration};
2019
use url::{self, Url};
2120

2221
use {Model, User, Keyword, Version};
@@ -224,7 +223,7 @@ impl Crate {
224223

225224
pub fn valid_name(name: &str) -> bool {
226225
if name.len() == 0 { return false }
227-
name.char_at(0).is_alphabetic() &&
226+
name.chars().next().unwrap().is_alphabetic() &&
228227
name.chars().all(|c| c.is_alphanumeric() || c == '_' || c == '-') &&
229228
name.chars().all(|c| c.is_ascii())
230229
}
@@ -448,7 +447,7 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
448447
WHERE q @@ textsearchable_index_col".to_string())
449448
}).or_else(|| {
450449
query.get("letter").map(|letter| {
451-
pattern = format!("{}%", letter.char_at(0)
450+
pattern = format!("{}%", letter.chars().next().unwrap()
452451
.to_lowercase().collect::<String>());
453452
needs_pattern = true;
454453
(format!("SELECT * FROM crates WHERE canon_crate_name(name) \
@@ -777,7 +776,7 @@ fn read_fill<R: Read + ?Sized>(r: &mut R, mut slice: &mut [u8])
777776
let n = try!(r.read(slice));
778777
if n == 0 {
779778
return Err(io::Error::new(io::ErrorKind::Other,
780-
"end of file reached", None))
779+
"end of file reached"))
781780
}
782781
slice = &mut mem::replace(&mut slice, &mut [])[n..];
783782
}

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(collections, core, std_misc, io, str_char)]
2-
31
#[macro_use] extern crate log;
42
extern crate postgres as pg;
53
extern crate rustc_serialize;

src/s3/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ name = "s3"
44
version = "0.0.1"
55
authors = []
66

7-
[[lib]]
7+
[lib]
88

99
name = "s3"
1010
path = "lib.rs"
1111

1212
[dependencies]
13-
openssl = "0.5"
13+
openssl = "0.6"
1414
time = "0.1.0"
1515
curl = "0.2"
1616
rustc-serialize = "0.3"

src/tests/all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![deny(warnings)]
2-
#![feature(io, path_ext, convert)]
2+
#![feature(io, path_ext)]
33

44
extern crate cargo_registry;
55
extern crate conduit_middleware;

src/util/errors.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,26 @@ impl<E: CargoError> fmt::Display for ChainedError<E> {
109109

110110
impl<E: Error + Send + 'static> From<E> for Box<CargoError> {
111111
fn from(err: E) -> Box<CargoError> {
112-
Box::new(err)
112+
struct Shim<E>(E);
113+
impl<E: Error + Send + 'static> CargoError for Shim<E> {
114+
fn description(&self) -> &str { Error::description(&self.0) }
115+
}
116+
impl<E: fmt::Display> fmt::Display for Shim<E> {
117+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
118+
self.0.fmt(f)
119+
}
120+
}
121+
Box::new(Shim(err))
113122
}
114123
}
115124

125+
impl CargoError for ::curl::ErrCode {
126+
fn description(&self) -> &str { Error::description(self) }
127+
}
128+
impl CargoError for ::rustc_serialize::json::DecoderError {
129+
fn description(&self) -> &str { Error::description(self) }
130+
}
131+
116132
// =============================================================================
117133
// Concrete errors
118134

src/util/io_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<R: Read> Read for LimitErrorReader<R> {
1616
match self.inner.read(buf) {
1717
Ok(0) if self.inner.limit() == 0 => {
1818
Err(io::Error::new(io::ErrorKind::Other,
19-
"maximum limit reached when reading", None))
19+
"maximum limit reached when reading"))
2020
}
2121
e => e,
2222
}

src/version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::collections::HashMap;
2-
use std::time::Duration;
32
use rustc_serialize::json;
43
use time::Timespec;
54

65
use conduit::{Request, Response};
76
use conduit_router::RequestParams;
8-
use pg;
97
use pg::types::Slice;
8+
use pg;
109
use semver;
10+
use time::Duration;
1111
use url;
1212

1313
use {Model, Crate, User};

0 commit comments

Comments
 (0)