Skip to content

Commit 63255d6

Browse files
fengmk2Copilot
andcommitted
Update crates/vite_package_manager/src/package_manager.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 15dfbe2 commit 63255d6

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

crates/vite_error/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ pub enum Error {
154154
UserCancelled,
155155

156156
#[error("Hash mismatch: expected {expected}, got {actual}")]
157-
HashMismatch { expected: String, actual: String },
157+
HashMismatch { expected: Str, actual: Str },
158158

159159
#[error("Invalid hash format: {0}")]
160-
InvalidHashFormat(String),
160+
InvalidHashFormat(Str),
161161

162162
#[error("Unsupported hash algorithm: {0}")]
163-
UnsupportedHashAlgorithm(String),
163+
UnsupportedHashAlgorithm(Str),
164164

165165
#[error(transparent)]
166166
AnyhowError(#[from] anyhow::Error),

crates/vite_package_manager/src/package_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl PackageManagerBuilder {
9797
if version == "latest" {
9898
version = get_latest_version(package_manager_type).await?;
9999
should_update_package_manager_field = true;
100-
hash = None; // Reset hash when fetching latest
100+
hash = None; // Reset hash when fetching latest since hash is version-specific
101101
}
102102

103103
// handle yarn >= 2.0.0 to use `@yarnpkg/cli-dist` as package name

crates/vite_package_manager/src/request.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub async fn download_and_extract_tgz_with_hash(
188188
/// Computes the hash of the given content using the specified digest algorithm.
189189
///
190190
/// # Type Parameters
191-
/// * `D` - A type that implements the [`Digest`](sha2::Digest) trait, such as `Sha256`, `Sha512`, etc.
191+
/// * `D` - A type that implements the [`Digest`] trait, such as `Sha256`, `Sha512`, etc.
192192
///
193193
/// # Arguments
194194
/// * `content` - The byte slice to hash.
@@ -221,7 +221,7 @@ pub async fn verify_file_hash(
221221
let (algorithm, expected_hex) = if let Some((algo, hash)) = expected_hash.split_once('.') {
222222
(algo, hash)
223223
} else {
224-
return Err(Error::InvalidHashFormat(expected_hash.to_string()));
224+
return Err(Error::InvalidHashFormat(expected_hash.into()));
225225
};
226226

227227
// Calculate the actual hash based on the algorithm
@@ -230,13 +230,13 @@ pub async fn verify_file_hash(
230230
"sha256" => compute_hash::<Sha256>(&content),
231231
"sha224" => compute_hash::<Sha224>(&content),
232232
"sha1" => compute_hash::<Sha1>(&content),
233-
_ => return Err(Error::UnsupportedHashAlgorithm(algorithm.to_string())),
233+
_ => return Err(Error::UnsupportedHashAlgorithm(algorithm.into())),
234234
};
235235

236236
if actual_hex != expected_hex {
237237
return Err(Error::HashMismatch {
238-
expected: expected_hash.to_string(),
239-
actual: format!("{}.{}", algorithm, actual_hex),
238+
expected: expected_hash.into(),
239+
actual: format!("{}.{}", algorithm, actual_hex).into(),
240240
});
241241
}
242242

0 commit comments

Comments
 (0)