|
1 | 1 | use std::{hash::Hasher, path::PathBuf};
|
2 | 2 |
|
3 |
| -use anyhow::{bail, Context}; |
| 3 | +use anyhow::Context; |
4 | 4 | use deno_core::error::AnyError;
|
5 | 5 | use futures::{io::AllowStdIo, StreamExt};
|
6 | 6 | use reqwest::Url;
|
7 | 7 | use tokio::io::AsyncWriteExt;
|
8 | 8 | use tokio_util::compat::FuturesAsyncWriteCompatExt;
|
9 |
| -use tracing::{debug, error, info, info_span, instrument, trace, Instrument}; |
| 9 | +use tracing::{info, info_span, instrument, trace, Instrument}; |
10 | 10 | use xxhash_rust::xxh3::Xxh3;
|
11 | 11 |
|
12 | 12 | #[instrument(fields(%kind, url = %url))]
|
@@ -92,17 +92,6 @@ pub async fn fetch_and_cache_from_url(
|
92 | 92 | .await
|
93 | 93 | .context("failed to download")?;
|
94 | 94 |
|
95 |
| - let len = resp |
96 |
| - .headers() |
97 |
| - .get(header::CONTENT_LENGTH) |
98 |
| - .map(|it| it.to_str().map_err(AnyError::new)) |
99 |
| - .transpose()? |
100 |
| - .map(|it| it.parse::<usize>().map_err(AnyError::new)) |
101 |
| - .transpose()? |
102 |
| - .context("invalid Content-Length header")?; |
103 |
| - |
104 |
| - debug!(total_bytes = len); |
105 |
| - |
106 | 95 | let file = tokio::fs::File::create(&filepath)
|
107 | 96 | .await
|
108 | 97 | .context("failed to create file")?;
|
@@ -131,23 +120,18 @@ pub async fn fetch_and_cache_from_url(
|
131 | 120 | faster_hex::hex_string(&hasher.finish().to_be_bytes())
|
132 | 121 | };
|
133 | 122 |
|
134 |
| - if written == len as u64 { |
135 |
| - info!({ bytes_written = written, checksum = &checksum_str }, "done"); |
| 123 | + info!({ bytes_written = written, checksum = &checksum_str }, "done"); |
136 | 124 |
|
137 |
| - let mut checksum_file = tokio::fs::File::create(&checksum_path) |
138 |
| - .await |
139 |
| - .context("failed to create checksum file")?; |
| 125 | + let mut checksum_file = tokio::fs::File::create(&checksum_path) |
| 126 | + .await |
| 127 | + .context("failed to create checksum file")?; |
140 | 128 |
|
141 |
| - let _ = checksum_file |
142 |
| - .write(checksum_str.as_bytes()) |
143 |
| - .await |
144 |
| - .context("failed to write checksum to file system")?; |
| 129 | + let _ = checksum_file |
| 130 | + .write(checksum_str.as_bytes()) |
| 131 | + .await |
| 132 | + .context("failed to write checksum to file system")?; |
145 | 133 |
|
146 |
| - Ok(filepath) |
147 |
| - } else { |
148 |
| - error!({ expected = len, got = written }, "bytes mismatch"); |
149 |
| - bail!("error copying data to file: expected {len} length, but got {written}"); |
150 |
| - } |
| 134 | + Ok(filepath) |
151 | 135 | }
|
152 | 136 | }
|
153 | 137 | .instrument(span)
|
|
0 commit comments