aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive.rs
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2021-03-28 20:41:07 +0000
committerSven-Hendrik Haase <svenstaro@gmail.com>2021-03-28 20:41:07 +0000
commit906af1587144dd4b3caecacdff5ea834012cffa4 (patch)
tree57ca5b252dcfc76fa79b7a0f41584527b4188cff /src/archive.rs
parentChange start message without arguments to be a bit more clear (diff)
downloadminiserve-906af1587144dd4b3caecacdff5ea834012cffa4.tar.gz
miniserve-906af1587144dd4b3caecacdff5ea834012cffa4.zip
Refuse to start without explicit path if not attached to interactive terminal
Diffstat (limited to 'src/archive.rs')
-rw-r--r--src/archive.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/archive.rs b/src/archive.rs
index 894ee3f..4df3a31 100644
--- a/src/archive.rs
+++ b/src/archive.rs
@@ -220,15 +220,18 @@ where
let mut buffer = Vec::new();
while !paths_queue.is_empty() {
let next = paths_queue.pop().ok_or_else(|| {
- ContextualError::CustomError("Could not get path from queue".to_string())
+ ContextualError::ArchiveCreationDetailError("Could not get path from queue".to_string())
})?;
let current_dir = next.as_path();
let directory_entry_iterator = std::fs::read_dir(current_dir)
.map_err(|e| ContextualError::IoError("Could not read directory".to_string(), e))?;
- let zip_directory =
- Path::new(zip_root_folder_name).join(current_dir.strip_prefix(directory).map_err(
- |_| ContextualError::CustomError("Could not append base directory".to_string()),
- )?);
+ let zip_directory = Path::new(zip_root_folder_name).join(
+ current_dir.strip_prefix(directory).map_err(|_| {
+ ContextualError::ArchiveCreationDetailError(
+ "Could not append base directory".to_string(),
+ )
+ })?,
+ );
for entry in directory_entry_iterator {
let entry_path = entry
@@ -259,10 +262,14 @@ where
zip_writer
.start_file(relative_path.to_string_lossy(), options)
.map_err(|_| {
- ContextualError::CustomError("Could not add file path to ZIP".to_string())
+ ContextualError::ArchiveCreationDetailError(
+ "Could not add file path to ZIP".to_string(),
+ )
})?;
zip_writer.write(buffer.as_ref()).map_err(|_| {
- ContextualError::CustomError("Could not write file to ZIP".to_string())
+ ContextualError::ArchiveCreationDetailError(
+ "Could not write file to ZIP".to_string(),
+ )
})?;
buffer.clear();
} else if entry_metadata.is_dir() {
@@ -270,7 +277,7 @@ where
zip_writer
.add_directory(relative_path.to_string_lossy(), options)
.map_err(|_| {
- ContextualError::CustomError(
+ ContextualError::ArchiveCreationDetailError(
"Could not add directory path to ZIP".to_string(),
)
})?;
@@ -280,7 +287,9 @@ where
}
zip_writer.finish().map_err(|_| {
- ContextualError::CustomError("Could not finish writing ZIP archive".to_string())
+ ContextualError::ArchiveCreationDetailError(
+ "Could not finish writing ZIP archive".to_string(),
+ )
})?;
Ok(())
}