From 96778d8e931342bca6253fe8ebbf3242aaaab217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 5 Sep 2016 21:54:59 +0200 Subject: [PATCH] Fixing content path creation --- dapps/src/apps/fetcher.rs | 6 +++++- dapps/src/handlers/fetch.rs | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dapps/src/apps/fetcher.rs b/dapps/src/apps/fetcher.rs index ea48e821f..f5d402a15 100644 --- a/dapps/src/apps/fetcher.rs +++ b/dapps/src/apps/fetcher.rs @@ -197,7 +197,7 @@ impl fmt::Display for ValidationError { match *self { ValidationError::Io(ref io) => write!(f, "Unexpected IO error occured: {:?}", io), ValidationError::Zip(ref zip) => write!(f, "Unable to read ZIP archive: {:?}", zip), - ValidationError::InvalidContentId => write!(f, "ID is invalid. It should be 26 bits keccak hash of content."), + ValidationError::InvalidContentId => write!(f, "ID is invalid. It should be 256 bits keccak hash of content."), ValidationError::ManifestNotFound => write!(f, "Downloaded Dapp bundle did not contain valid manifest.json file."), ValidationError::ManifestSerialization(ref err) => { write!(f, "There was an error during Dapp Manifest serialization: {:?}", err) @@ -233,6 +233,10 @@ impl ContentValidator for ContentInstaller { type Result = PathBuf; fn validate_and_install(&self, path: PathBuf) -> Result<(String, PathBuf), ValidationError> { + // Create dir + try!(fs::create_dir_all(&self.content_path)); + + // And prepare path for a file let filename = path.file_name().expect("We always fetch a file."); let mut content_path = self.content_path.clone(); content_path.push(&filename); diff --git a/dapps/src/handlers/fetch.rs b/dapps/src/handlers/fetch.rs index 8c7702b18..790bf4710 100644 --- a/dapps/src/handlers/fetch.rs +++ b/dapps/src/handlers/fetch.rs @@ -16,7 +16,7 @@ //! Hyper Server Handler that fetches a file during a request (proxy). -use std::fmt; +use std::{fs, fmt}; use std::path::PathBuf; use std::sync::{mpsc, Arc}; use std::sync::atomic::AtomicBool; @@ -165,7 +165,7 @@ impl server::Handler for ContentFetcherHandler< match rec { // Unpack and validate Ok(Ok(path)) => { - trace!(target: "dapps", "Fetching content finished. Starting validation."); + trace!(target: "dapps", "Fetching content finished. Starting validation ({:?})", path); Self::close_client(&mut self.client); // Unpack and verify let state = match self.installer.validate_and_install(path.clone()) { @@ -181,8 +181,7 @@ impl server::Handler for ContentFetcherHandler< Ok(result) => FetchState::Done(result) }; // Remove temporary zip file - // TODO [todr] Uncomment me - // let _ = fs::remove_file(path); + let _ = fs::remove_file(path); (Some(state), Next::write()) }, Ok(Err(e)) => {