|
1 | 1 | use std::{ |
2 | 2 | collections::{HashMap, HashSet}, |
| 3 | + env, |
3 | 4 | fs::Permissions, |
4 | 5 | os::unix::fs::PermissionsExt, |
5 | 6 | path::PathBuf, |
@@ -95,7 +96,7 @@ impl Downloader<'_> { |
95 | 96 | result.to_hex().to_string() |
96 | 97 | }; |
97 | 98 |
|
98 | | - let (mut provisional_path, final_dir) = if let Some(ref out) = options.output_path { |
| 99 | + let (provisional_path, final_dir) = if let Some(ref out) = options.output_path { |
99 | 100 | if out.ends_with('/') { |
100 | 101 | let dir = PathBuf::from(out); |
101 | 102 | let base = extract_filename_from_url(&options.url).unwrap_or_else(hash_fallback); |
@@ -202,14 +203,16 @@ impl Downloader<'_> { |
202 | 203 | .and_then(|header| header.to_str().ok()) |
203 | 204 | .and_then(extract_filename); |
204 | 205 |
|
205 | | - if let Some(name) = header_name { |
206 | | - provisional_path = if let Some(ref dir) = final_dir { |
207 | | - dir.join(name.clone()) |
208 | | - } else { |
209 | | - PathBuf::from(name.clone()) |
210 | | - }; |
211 | | - } |
212 | | - let final_target = provisional_path.clone(); |
| 206 | + let final_target = match &options.output_path { |
| 207 | + Some(_) => provisional_path, |
| 208 | + None => match header_name { |
| 209 | + Some(ref name) => final_dir |
| 210 | + .as_ref() |
| 211 | + .map(|dir| dir.join(name)) |
| 212 | + .unwrap_or_else(|| PathBuf::from(name)), |
| 213 | + None => provisional_path, |
| 214 | + }, |
| 215 | + }; |
213 | 216 |
|
214 | 217 | if final_target.exists() && !part_path.exists() { |
215 | 218 | match options.file_mode { |
|
0 commit comments