Skip to content

Commit

Permalink
Fix file upload where header wasn't sent.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethankhall committed Jan 18, 2019
1 parent 5d74ed3 commit 12facb9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/crom_lib/artifact/compress.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
use std::path::{PathBuf, Path};

use libflate::gzip::Encoder;
use std::io::Write;
Expand Down Expand Up @@ -33,6 +33,7 @@ fn zip(
let mut zip = zip::ZipWriter::new(output_file);

for (name, path) in artifacts {
debug!("Compressing {} located at {}", name, path);
let name = name.to_string();
let options =
zip::write::FileOptions::default().compression_method(zip::CompressionMethod::Stored);
Expand All @@ -43,7 +44,11 @@ fn zip(
}

let mut art_path = root_path.clone();
art_path.push(path);
art_path.push(Path::new(path));

if !art_path.exists() {
return Err(ErrorContainer::Compress(CompressError::UnableToFindArtifact(art_path.to_str().unwrap().to_string())));
}

let mut file = File::open(art_path)?;
let mut contents: Vec<u8> = Vec::new();
Expand All @@ -69,8 +74,8 @@ fn tgz(
let mut art_path = root_path.clone();
art_path.push(path);

let mut f = File::open(art_path).unwrap();
ar.append_file(name, &mut f).unwrap();
let mut f = File::open(art_path)?;
ar.append_file(name, &mut f)?;
}

let mut encoder = Encoder::new(output_file)?;
Expand Down
2 changes: 1 addition & 1 deletion src/crom_lib/artifact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn upload_artifacts(

match res {
Err(e) => {
error!("Error while uploading artifact: {:?}", e);
error!("Error while building upload request: {:?}", e);
return Err(ErrorContainer::Artifact(ArtifactError::FailedUpload));
}
Ok(bodys) => upload_requests.extend(bodys),
Expand Down
2 changes: 2 additions & 0 deletions src/crom_lib/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum ErrorContainer {
pub enum CompressError {
ZipFailure(String),
ZipFileNameErr(String),
UnableToFindArtifact(String),
UnableToCompressArtifacts(String),
}

#[derive(Debug, PartialEq)]
Expand Down
5 changes: 2 additions & 3 deletions src/crom_lib/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ pub fn make_file_upload_request(
builder.header(key, value);
}

Ok(Request::builder()
.method("POST")
.uri(url.as_str())
Ok(builder
.header(USER_AGENT, format!("crom/{}", env!("CARGO_PKG_VERSION")))
.header(CONTENT_TYPE, mime.to_string())
.header(CONTENT_LENGTH, size)
Expand Down Expand Up @@ -86,6 +84,7 @@ pub fn make_post(

#[cfg(test)]
pub fn make_github_auth_headers() -> Result<HashMap<HeaderName, HeaderValue>, ErrorContainer> {
warn!("Using debug GITHUB headers!");
Ok(HashMap::new())
}

Expand Down

0 comments on commit 12facb9

Please sign in to comment.