aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive.rs
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2019-04-27 19:31:07 +0000
committerGitHub <noreply@github.com>2019-04-27 19:31:07 +0000
commit18fcc8e699897ceca75920722531b79d909f28fc (patch)
tree9e855f3afbbe8237a09c9c364832f8c5aa4e57e8 /src/archive.rs
parentDescribe hashed password feature in README (diff)
parentCombine ContextualError and ContextualErrorKind into one (diff)
downloadminiserve-18fcc8e699897ceca75920722531b79d909f28fc.tar.gz
miniserve-18fcc8e699897ceca75920722531b79d909f28fc.zip
Merge pull request #88 from KSXGitHub/combine-contextual-error
Combine ContextualError and ContextualErrorKind into one
Diffstat (limited to 'src/archive.rs')
-rw-r--r--src/archive.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/archive.rs b/src/archive.rs
index b5788f5..a76446a 100644
--- a/src/archive.rs
+++ b/src/archive.rs
@@ -7,7 +7,7 @@ use std::path::PathBuf;
use strum_macros::{Display, EnumIter, EnumString};
use tar::Builder;
-use crate::errors::{ContextualError, ContextualErrorKind};
+use crate::errors::{ContextualError};
/// Available compression methods
#[derive(Deserialize, Clone, EnumIter, EnumString, Display)]
@@ -62,17 +62,17 @@ fn tgz_compress(dir: &PathBuf, skip_symlinks: bool) -> Result<(String, Bytes), C
let mut tgz_data = Bytes::new();
let tar_data = tar(src_dir, directory.to_string(), skip_symlinks).map_err(|e| {
- ContextualError::new(ContextualErrorKind::ArchiveCreationError(
+ ContextualError::ArchiveCreationError(
"tarball".to_string(),
Box::new(e),
- ))
+ )
})?;
let gz_data = gzip(&tar_data).map_err(|e| {
- ContextualError::new(ContextualErrorKind::ArchiveCreationError(
+ ContextualError::ArchiveCreationError(
"GZIP archive".to_string(),
Box::new(e),
- ))
+ )
})?;
tgz_data.extend_from_slice(&gz_data);
@@ -80,15 +80,15 @@ fn tgz_compress(dir: &PathBuf, skip_symlinks: bool) -> Result<(String, Bytes), C
Ok((dst_tgz_filename, tgz_data))
} else {
// https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.to_str
- Err(ContextualError::new(ContextualErrorKind::InvalidPathError(
+ Err(ContextualError::InvalidPathError(
"Directory name contains invalid UTF-8 characters".to_string(),
- )))
+ ))
}
} else {
// https://doc.rust-lang.org/std/path/struct.Path.html#method.file_name
- Err(ContextualError::new(ContextualErrorKind::InvalidPathError(
+ Err(ContextualError::InvalidPathError(
"Directory name terminates in \"..\"".to_string(),
- )))
+ ))
}
}
@@ -105,20 +105,20 @@ fn tar(
tar_builder
.append_dir_all(inner_folder, &src_dir)
.map_err(|e| {
- ContextualError::new(ContextualErrorKind::IOError(
+ ContextualError::IOError(
format!(
"Failed to append the content of {} to the TAR archive",
&src_dir
),
e,
- ))
+ )
})?;
let tar_content = tar_builder.into_inner().map_err(|e| {
- ContextualError::new(ContextualErrorKind::IOError(
+ ContextualError::IOError(
"Failed to finish writing the TAR archive".to_string(),
e,
- ))
+ )
})?;
Ok(tar_content)
@@ -127,22 +127,22 @@ fn tar(
/// Compresses a stream of bytes using the GZIP algorithm, and returns the resulting stream
fn gzip(mut data: &[u8]) -> Result<Vec<u8>, ContextualError> {
let mut encoder = Encoder::new(Vec::new()).map_err(|e| {
- ContextualError::new(ContextualErrorKind::IOError(
+ ContextualError::IOError(
"Failed to create GZIP encoder".to_string(),
e,
- ))
+ )
})?;
io::copy(&mut data, &mut encoder).map_err(|e| {
- ContextualError::new(ContextualErrorKind::IOError(
+ ContextualError::IOError(
"Failed to write GZIP data".to_string(),
e,
- ))
+ )
})?;
let data = encoder.finish().into_result().map_err(|e| {
- ContextualError::new(ContextualErrorKind::IOError(
+ ContextualError::IOError(
"Failed to write GZIP trailer".to_string(),
e,
- ))
+ )
})?;
Ok(data)