Upgrade curl to 0.3

This commit is contained in:
Danilo Bargen 2016-08-01 12:20:41 +02:00
commit 9e868cb728
4 changed files with 27 additions and 49 deletions

37
Cargo.lock generated
View file

@ -4,7 +4,7 @@ version = "0.2.0"
dependencies = [
"ansi_term 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy 0.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"curl 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"curl 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"docopt 0.6.82 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
@ -54,19 +54,17 @@ dependencies = [
[[package]]
name = "curl"
version = "0.2.19"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"curl-sys 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"curl-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "curl-sys"
version = "0.1.34"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
@ -127,16 +125,6 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "idna"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
@ -332,28 +320,11 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-bidi"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-normalization"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "url"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "user32-sys"
version = "0.2.0"

View file

@ -20,7 +20,7 @@ dev = ["clippy"]
log = "^0.3"
xdg = "^2.0"
tar = "^0.4"
curl = "^0.2"
curl = "^0.3"
time = "^0.1"
flate2 = "^0.2"
docopt = "^0.6"

View file

@ -8,7 +8,7 @@ use std::path::PathBuf;
use xdg::BaseDirectories;
use flate2::read::GzDecoder;
use tar::Archive;
use curl::http;
use curl::easy::Easy as CurlEasy;
use walkdir::{WalkDir, WalkDirIterator, DirEntry};
use time;
@ -55,14 +55,21 @@ impl Cache {
}
/// Download the archive
fn download(&self) -> Result<http::Response, TealdeerError> {
let resp = try!(
http::handle()
.follow_location(1)
.get(&self.url[..])
.exec()
);
Ok(resp)
fn download(&self) -> Result<Vec<u8>, TealdeerError> {
let mut handle = CurlEasy::new();
try!(handle.url(&self.url));
try!(handle.follow_location(true));
try!(handle.fail_on_error(true));
let mut buf = Vec::new();
{
let mut transfer = handle.transfer();
try!(transfer.write_function(|data| {
buf.extend_from_slice(data);
Ok(data.len())
}));
try!(transfer.perform());
}
Ok(buf)
}
/// Decompress and open the archive
@ -74,10 +81,10 @@ impl Cache {
/// Update the pages cache.
pub fn update(&self) -> Result<(), TealdeerError> {
// First, download the compressed data
let response = try!(self.download());
let bytes: Vec<u8> = try!(self.download());
// Decompress the response body into an `Archive`
let mut archive = try!(self.decompress(response.get_body()));
let mut archive = try!(self.decompress(&bytes[..]));
// Determine paths
let cache_dir = try!(self.get_cache_dir());

View file

@ -1,4 +1,4 @@
use curl::ErrCode;
use curl::Error as CurlError;
#[derive(Debug)]
pub enum TealdeerError {
@ -6,8 +6,8 @@ pub enum TealdeerError {
UpdateError(String),
}
impl From<ErrCode> for TealdeerError {
fn from(err: ErrCode) -> TealdeerError {
TealdeerError::UpdateError(err.to_string())
impl From<CurlError> for TealdeerError {
fn from(err: CurlError) -> TealdeerError {
TealdeerError::UpdateError(format!("Curl error: {}", err.to_string()))
}
}