Skip to content

Commit

Permalink
Upgrade to actix v1 and ipfs-api v0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Oct 18, 2019
1 parent f33d837 commit ea34687
Show file tree
Hide file tree
Showing 8 changed files with 1,134 additions and 1,065 deletions.
2,102 changes: 1,086 additions & 1,016 deletions Cargo.lock

Large diffs are not rendered by default.

37 changes: 18 additions & 19 deletions git-lfs-ipfs-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ authors = ["Sameer Puri <purisame@spuri.io>"]
edition = "2018"

[dependencies]
actix-web = "0.7"
actix = "0.7"
serde_json = "1.0"
futures = "0.1.25"
failure = "0.1"
env_logger = "0.6"
bytes = "0.4"
cid = "0.3"
git-lfs-spec = { path = "../git-lfs-spec", version = "0.1" }
clap = "2.32"
multihash = "0.8"
ipfs-api = { version = "0.5.0-alpha2", git = "https://github.com/ferristseng/rust-ipfs-api", features = ["actix"], default-features = false }
hex = "0.3"
url = "1.7"
lazy_static = "1.2"
serde = "1.0"
publicsuffix = "1.5"
path-clean = "0.1"
actix = "0.8"
serde_json = "1"
futures = "0"
derive_more = "0"
env_logger = "0"
bytes = "0"
cid = "0"
git-lfs-spec = { path = "../git-lfs-spec", version = "0" }
clap = "2"
multihash = "0"
ipfs-api = { version = "0.5.2", features = ["actix"], default-features = false }
hex = "0"
url = "2"
lazy_static = "1"
serde = "1"
publicsuffix = "1"
path-clean = "0"

[dev-dependencies]
pretty_assertions = "0.5"
pretty_assertions = "0"
5 changes: 2 additions & 3 deletions git-lfs-ipfs-cli/src/clean.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io::{self, Write};

use actix::prelude::*;
use futures::prelude::*;

use crate::error::CliError;

Expand All @@ -20,11 +19,11 @@ impl Actor for Clean {
actix::fut::wrap_future(
ipfs_api::IpfsClient::default()
.add(io::stdin())
.map_err(CliError::IpfsApiError)
.map_err(|err| CliError::IpfsApiError(err.to_string()))
.map(|add_response| {
ipfs_api::IpfsClient::default()
.block_get(&add_response.hash)
.map_err(CliError::IpfsApiError)
.map_err(|err| CliError::IpfsApiError(err.to_string()))
})
.flatten_stream()
.fold(io::stdout(), |mut acc, x| {
Expand Down
19 changes: 9 additions & 10 deletions git-lfs-ipfs-cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use failure::Fail;

use git_lfs_spec::transfer::custom;

#[derive(Fail, Debug)]
#[derive(Display, Debug)]
pub enum CliError {
#[fail(display = "{}", _0)]
SerdeJsonError(#[cause] serde_json::error::Error),
#[fail(display = "{}", _0)]
Io(#[cause] std::io::Error),
#[fail(display = "Input was an unexpected event {:?}", _0)]
#[display(fmt = "{}", _0)]
SerdeJsonError(serde_json::error::Error),
#[display(fmt = "{}", _0)]
Io(std::io::Error),
#[display(fmt = "Input was an unexpected event {:?}", _0)]
UnexpectedEvent(custom::Event),
#[fail(display = "Error with a request to the IPFS API {:?}", _0)]
IpfsApiError(ipfs_api::response::Error),
// TODO: Actix developers made the Actix error !Send + !Sync. Once this is handled in rust-ipfs-api, can restore the error here.
#[display(fmt = "Error with a request to the IPFS API {:?}", _0)]
IpfsApiError(String),
}
19 changes: 9 additions & 10 deletions git-lfs-ipfs-cli/src/ipfs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use failure::Fail;
use lazy_static::lazy_static;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt::Display;
use std::str::FromStr;
use std::path::PathBuf;
use std::str::FromStr;
use url::Url;

pub const EMPTY_FOLDER_HASH: &str = "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn";
Expand Down Expand Up @@ -32,21 +31,21 @@ pub fn sha256_to_cid(codec: cid::Codec, sha256_str: &str) -> Option<cid::Cid> {
})
}

#[derive(Fail, Debug, Eq, PartialEq)]
#[derive(Display, Debug, Eq, PartialEq)]
pub enum PathParseError {
#[fail(display = "unable to parse cid: {}", _0)]
#[display(fmt = "unable to parse cid: {}", _0)]
CidError(cid::Error),
#[fail(display = "invalid domain: {}", _0)]
#[display(fmt = "invalid domain: {}", _0)]
DnsLinkDomainInvalid(String),
#[fail(display = "errors during UTS#46 processing: {}", _0)]
#[display(fmt = "errors during UTS#46 processing: {}", _0)]
DnsLinkUnicodeError(String),
#[fail(display = "unable to parse suffix: {}", _0)]
#[display(fmt = "unable to parse suffix: {}", _0)]
SuffixError(std::string::ParseError),
#[fail(display = "suffix is not absolute: {}", _0)]
#[display(fmt = "suffix is not absolute: {}", _0)]
SuffixNotAbsolute(String),
#[fail(display = "unexpected prefix: {} (must be /ipfs/ or /ipns/)", _0)]
#[display(fmt = "unexpected prefix: {} (must be /ipfs/ or /ipns/)", _0)]
UnknownPrefix(String),
#[fail(display = "expected cid, got dnslink record")]
#[display(fmt = "expected cid, got dnslink record")]
ExpectedCid,
}

Expand Down
5 changes: 4 additions & 1 deletion git-lfs-ipfs-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#[macro_use]
extern crate clap;

#[macro_use]
extern crate derive_more;

#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;

use actix::prelude::*;
use actix::{prelude::*, System};

mod clean;
mod error;
Expand Down
1 change: 1 addition & 0 deletions git-lfs-ipfs-cli/src/smudge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl Actor for Smudge {
.cat(&crate::ipfs::Path::ipfs(cid).to_string())
})
.flatten_stream()
.map_err(|err| err.to_string())
.map_err(CliError::IpfsApiError),
)
.and_then(|b: bytes::Bytes, actor: &mut Self, ctx| {
Expand Down
11 changes: 5 additions & 6 deletions git-lfs-ipfs-cli/src/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use actix::prelude::*;
use futures::{future, prelude::*, stream};

use crate::error::CliError;
use git_lfs_spec::{
transfer::custom,
};
use git_lfs_spec::transfer::custom;

#[derive(Debug, Clone)]
struct Input(custom::Event);
Expand Down Expand Up @@ -60,10 +58,10 @@ impl StreamHandler<Input, CliError> for Transfer {
println!("{{}}");
}
(None, event) => {
panic!(CliError::UnexpectedEvent(event.0));
panic!("{}", CliError::UnexpectedEvent(event.0));
}
(Some(_), Input(custom::Event::Init(init))) => {
panic!(CliError::UnexpectedEvent(custom::Event::Init(init)));
panic!("{}", CliError::UnexpectedEvent(custom::Event::Init(init)));
}
(Some(_), Input(custom::Event::Terminate)) => {
System::current().stop();
Expand All @@ -74,7 +72,7 @@ impl StreamHandler<Input, CliError> for Transfer {
Ok(response) => {
println!(
"{}",
serde_json::to_string(&response.0s)
serde_json::to_string(&response.0)
.expect("Failed to serialize an event")
);
actix::fut::ok(())
Expand Down Expand Up @@ -136,6 +134,7 @@ impl Handler<Input> for Engine {
actix::fut::wrap_stream(
ipfs_api::IpfsClient::default()
.block_get(&crate::ipfs::Path::ipfs(cid.clone()).to_string())
.map_err(|err| err.to_string())
.map_err(CliError::IpfsApiError)
.and_then(move |x| {
output.write_all(&x).map(|_| x.len()).map_err(CliError::Io)
Expand Down

0 comments on commit ea34687

Please sign in to comment.