Skip to content

Commit

Permalink
refactor(core): move integrity checksum type to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
beeb committed Sep 9, 2024
1 parent 209bf42 commit ea47a43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
7 changes: 0 additions & 7 deletions crates/core/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use crate::{
registry::parse_version_req,
utils::{run_git_command, sanitize_filename},
};
use derive_more::{Display, From};
use reqwest::IntoUrl;
use semver::Version;
use std::{
borrow::Cow,
fs,
io::Cursor,
path::{Path, PathBuf},
Expand All @@ -18,11 +16,6 @@ use tokio::io::AsyncWriteExt as _;

pub type Result<T> = std::result::Result<T, DownloadError>;

#[derive(Debug, Clone, PartialEq, Eq, Hash, From, Display)]
#[from(Cow<'static, str>, String, &'static str)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IntegrityChecksum(pub String);

pub async fn download_file(url: impl IntoUrl, folder_path: impl AsRef<Path>) -> Result<PathBuf> {
let resp = reqwest::get(url).await?;
let mut resp = resp.error_for_status()?;
Expand Down
13 changes: 9 additions & 4 deletions crates/core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::{
download::IntegrityChecksum,
errors::{DownloadError, InstallError},
};
use crate::errors::{DownloadError, InstallError};
use derive_more::derive::{Display, From};
use ignore::{WalkBuilder, WalkState};
use path_slash::PathExt as _;
use regex::Regex;
use sha2::{Digest as _, Sha256};
use std::{
borrow::Cow,
env,
ffi::OsStr,
fs,
Expand All @@ -27,6 +26,12 @@ pub enum UrlType {
Http,
}

/// Wrapper type for the string reprentation of an integrity checksum (SHA256)
#[derive(Debug, Clone, PartialEq, Eq, Hash, From, Display)]
#[from(Cow<'static, str>, String, &'static str)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IntegrityChecksum(pub String);

/// Read a file contents into a vector of bytes
pub fn read_file(path: impl AsRef<Path>) -> Result<Vec<u8>, std::io::Error> {
let f = fs::File::open(path)?;
Expand Down

0 comments on commit ea47a43

Please sign in to comment.