Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Commit 252e07e

Browse files
committed
fix file target when output path is provided
1 parent 8b87ffa commit 252e07e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/downloader.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
collections::{HashMap, HashSet},
3+
env,
34
fs::Permissions,
45
os::unix::fs::PermissionsExt,
56
path::PathBuf,
@@ -95,7 +96,7 @@ impl Downloader<'_> {
9596
result.to_hex().to_string()
9697
};
9798

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 {
99100
if out.ends_with('/') {
100101
let dir = PathBuf::from(out);
101102
let base = extract_filename_from_url(&options.url).unwrap_or_else(hash_fallback);
@@ -202,14 +203,16 @@ impl Downloader<'_> {
202203
.and_then(|header| header.to_str().ok())
203204
.and_then(extract_filename);
204205

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+
};
213216

214217
if final_target.exists() && !part_path.exists() {
215218
match options.file_mode {

0 commit comments

Comments
 (0)