diff options
author | Vojtěch Pejša <vojtechpejsa7@gmail.com> | 2019-03-29 22:33:27 +0000 |
---|---|---|
committer | Vojtěch Pejša <vojtechpejsa7@gmail.com> | 2019-04-04 08:51:00 +0000 |
commit | 93ea625fe29ea02c5bda6b4f6361134a0fe667f0 (patch) | |
tree | be186a0ca7515457cfbc73ee1f315ddeaabdaee6 /src | |
parent | Fix syntax error and clippy warnings. (diff) | |
download | miniserve-93ea625fe29ea02c5bda6b4f6361134a0fe667f0.tar.gz miniserve-93ea625fe29ea02c5bda6b4f6361134a0fe667f0.zip |
Fix typos and indentation.
Diffstat (limited to 'src')
-rw-r--r-- | src/args.rs | 6 | ||||
-rw-r--r-- | src/file_upload.rs | 16 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/renderer.rs | 10 |
4 files changed, 17 insertions, 17 deletions
diff --git a/src/args.rs b/src/args.rs index 7fa5121..bb52824 100644 --- a/src/args.rs +++ b/src/args.rs @@ -53,8 +53,8 @@ struct CLIArgs { file_upload: bool, /// Enable overriding existing files during file upload - #[structopt(short = "o", long = "owerride-files")] - override_files: bool, + #[structopt(short = "o", long = "overwrite-files")] + overwrite_files: bool, } /// Checks wether an interface is valid, i.e. it can be parsed into an IP address @@ -108,7 +108,7 @@ pub fn parse_args() -> crate::MiniserveConfig { path_explicitly_chosen, no_symlinks: args.no_symlinks, random_route, - override_files: args.override_files, + overwrite_files: args.overwrite_files, file_upload: args.file_upload, } } diff --git a/src/file_upload.rs b/src/file_upload.rs index 88b8802..273d12c 100644 --- a/src/file_upload.rs +++ b/src/file_upload.rs @@ -22,9 +22,9 @@ struct QueryParameters { fn save_file( field: multipart::Field<dev::Payload>, file_path: PathBuf, - override_files: bool, + overwrite_files: bool, ) -> Box<Future<Item = i64, Error = FileUploadErrorKind>> { - if !override_files && file_path.exists() { + if !overwrite_files && file_path.exists() { return Box::new(future::err(FileUploadErrorKind::FileExist)); } let mut file = match std::fs::File::create(file_path) { @@ -50,7 +50,7 @@ fn save_file( fn handle_multipart( item: multipart::MultipartItem<dev::Payload>, mut file_path: PathBuf, - override_files: bool, + overwrite_files: bool, ) -> Box<Stream<Item = i64, Error = FileUploadErrorKind>> { match item { multipart::MultipartItem::Field(field) => { @@ -82,14 +82,14 @@ fn handle_multipart( } } file_path = file_path.join(f); - Box::new(save_file(field, file_path, override_files).into_stream()) + Box::new(save_file(field, file_path, overwrite_files).into_stream()) } Err(e) => err(e), } } multipart::MultipartItem::Nested(mp) => Box::new( mp.map_err(FileUploadErrorKind::MultipartError) - .map(move |item| handle_multipart(item, file_path.clone(), override_files)) + .map(move |item| handle_multipart(item, file_path.clone(), overwrite_files)) .flatten(), ), } @@ -124,16 +124,16 @@ pub fn upload_file(req: &HttpRequest<crate::MiniserveConfig>) -> FutureResponse< .to_owned(); let r_p2 = return_path.clone(); - // if target path is under app root directory save file + // If the target path is under the app root directory, save the file. let target_dir = match &app_root_dir.clone().join(path.clone()).canonicalize() { Ok(path) if path.starts_with(&app_root_dir) => path.clone(), _ => return Box::new(future::ok(HttpResponse::BadRequest().body("Invalid path"))), }; - let override_files = req.state().override_files; + let overwrite_files = req.state().overwrite_files; Box::new( req.multipart() .map_err(FileUploadErrorKind::MultipartError) - .map(move |item| handle_multipart(item, target_dir.clone(), override_files)) + .map(move |item| handle_multipart(item, target_dir.clone(), overwrite_files)) .flatten() .collect() .map(move |_| { diff --git a/src/main.rs b/src/main.rs index c8c13ea..0ca2fdf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ pub struct MiniserveConfig { pub file_upload: bool, /// Enable upload to override existing files - pub override_files: bool, + pub overwrite_files: bool, } fn main() { diff --git a/src/renderer.rs b/src/renderer.rs index 75d5c56..cb6d5d5 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -24,11 +24,11 @@ pub fn page( span #top { } h1 { (page_title) } @if file_upload { - form action={(upload_route) "?path=" (current_dir)} method="POST" enctype="multipart/form-data" { - p { "Select file to upload" } - input type="file" name="file_to_upload" {} - input type="submit" value="Upload file" {} - } + form action={(upload_route) "?path=" (current_dir)} method="POST" enctype="multipart/form-data" { + p { "Select file to upload" } + input type="file" name="file_to_upload" {} + input type="submit" value="Upload file" {} + } } div.download { (archive_button(archive::CompressionMethod::TarGz)) |