Skip to content

Commit 4a0c6e2

Browse files
fix: correct file creation path in download_file_with_progress_ureq function
fix #33
1 parent 1329275 commit 4a0c6e2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/aria2c.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub fn download_file_with_progress_ureq(
5252
.unwrap()
5353
.to_string();
5454

55+
let tmp_path = Path::new(&tmp_output_path);
5556
let output_path = Path::new(output_path);
5657
let mut req = ureq::get(url);
5758
let req =
@@ -70,7 +71,7 @@ pub fn download_file_with_progress_ureq(
7071
.set("Cache-Control", "no-cache");
7172

7273
let mut resp = req.call();
73-
let mut file = std::fs::File::create(output_path)?;
74+
let mut file = std::fs::File::create(&tmp_path)?;
7475
let mut total_size = 0;
7576
let mut downloaded_size = 0;
7677
let mut buffer = [0u8; 1024 * 1024];
@@ -104,6 +105,7 @@ pub fn download_file_with_progress_ureq(
104105
}
105106
}
106107
progress_callback(DownloadCallbackInfo { progress: 100.0 });
108+
std::fs::rename(&tmp_path, output_path)?;
107109
Ok(())
108110
}
109111

0 commit comments

Comments
 (0)