tighten visibility and clear the remaining mechanical lint noise
This commit is contained in:
+13
-14
@@ -9,20 +9,20 @@ use sha2::{Digest, Sha256};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum FfmpegStatus {
|
||||
pub(crate) enum FfmpegStatus {
|
||||
Ready,
|
||||
Missing,
|
||||
}
|
||||
|
||||
pub fn bin_dir(app_dir: &Path) -> PathBuf {
|
||||
pub(crate) fn bin_dir(app_dir: &Path) -> PathBuf {
|
||||
app_dir.join("bin")
|
||||
}
|
||||
|
||||
pub fn ffmpeg_path(app_dir: &Path) -> PathBuf {
|
||||
pub(crate) fn ffmpeg_path(app_dir: &Path) -> PathBuf {
|
||||
bin_dir(app_dir).join("ffmpeg.exe")
|
||||
}
|
||||
|
||||
pub fn check(app_dir: &Path) -> FfmpegStatus {
|
||||
pub(crate) fn check(app_dir: &Path) -> FfmpegStatus {
|
||||
if ffmpeg_path(app_dir).is_file() {
|
||||
FfmpegStatus::Ready
|
||||
} else {
|
||||
@@ -70,7 +70,7 @@ struct GithubAsset {
|
||||
browser_download_url: String,
|
||||
}
|
||||
|
||||
pub async fn download<F>(app_dir: &Path, mut on_progress: F) -> Result<()>
|
||||
pub(crate) async fn download<F>(app_dir: &Path, mut on_progress: F) -> Result<()>
|
||||
where
|
||||
F: FnMut(u64, Option<u64>) + Send,
|
||||
{
|
||||
@@ -143,7 +143,7 @@ where
|
||||
download_plain(&client, &asset.browser_download_url, &archive_path, on_progress)
|
||||
.await
|
||||
.with_context(|| format!("downloading {}", asset.browser_download_url))?;
|
||||
};
|
||||
}
|
||||
|
||||
let result = match source.kind {
|
||||
ArchiveKind::SevenZ => extract_ffmpeg_from_7z(&archive_path, dest),
|
||||
@@ -153,7 +153,7 @@ where
|
||||
result
|
||||
}
|
||||
|
||||
/// Fetch and parse a SHA-256 checksums file from GyanD.
|
||||
/// Fetch and parse a SHA-256 checksums file from `GyanD`.
|
||||
/// The file contains a line like:
|
||||
/// abc123def456... ffmpeg-8.1.1-full_build.7z
|
||||
async fn fetch_sha256(client: &reqwest::Client, url: &str) -> Result<[u8; 32]> {
|
||||
@@ -200,7 +200,7 @@ where
|
||||
{
|
||||
let resp = client.get(url).send().await?.error_for_status()?;
|
||||
let total = resp.content_length();
|
||||
let mut file = std::fs::File::create(dest).context("creating archive temp file")?;
|
||||
let mut file = File::create(dest).context("creating archive temp file")?;
|
||||
let mut downloaded = 0u64;
|
||||
let mut stream = resp.bytes_stream();
|
||||
while let Some(chunk) = stream.next().await {
|
||||
@@ -253,7 +253,7 @@ where
|
||||
let resp = client.get(url).send().await?.error_for_status()?;
|
||||
let total = resp.content_length();
|
||||
let mut hasher = Sha256::new();
|
||||
let mut file = std::fs::File::create(dest).context("creating archive temp file")?;
|
||||
let mut file = File::create(dest).context("creating archive temp file")?;
|
||||
let mut downloaded = 0u64;
|
||||
let mut stream = resp.bytes_stream();
|
||||
while let Some(chunk) = stream.next().await {
|
||||
@@ -266,7 +266,7 @@ where
|
||||
file.flush()?;
|
||||
let got: [u8; 32] = hasher.finalize().into();
|
||||
if &got != expected {
|
||||
drop(std::fs::remove_file(dest));
|
||||
drop(fs::remove_file(dest));
|
||||
bail!(
|
||||
"sha256 mismatch: expected {} got {}",
|
||||
hex::encode(expected),
|
||||
@@ -284,8 +284,7 @@ fn is_ffmpeg_entry(name: &str) -> bool {
|
||||
normalized
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.map(|leaf| leaf.eq_ignore_ascii_case("ffmpeg.exe"))
|
||||
.unwrap_or(false)
|
||||
.is_some_and(|leaf| leaf.eq_ignore_ascii_case("ffmpeg.exe"))
|
||||
}
|
||||
|
||||
fn extract_ffmpeg_from_7z(archive_path: &Path, dest: &Path) -> Result<()> {
|
||||
@@ -297,7 +296,7 @@ fn extract_ffmpeg_from_7z(archive_path: &Path, dest: &Path) -> Result<()> {
|
||||
drop(fs::remove_dir_all(&scratch));
|
||||
fs::create_dir_all(&scratch).context("create 7z scratch dir")?;
|
||||
|
||||
let file = std::fs::File::open(archive_path).context("opening 7z archive")?;
|
||||
let file = File::open(archive_path).context("opening 7z archive")?;
|
||||
let extract_result =
|
||||
sevenz_rust2::decompress_with_extract_fn(file, &scratch, |_, _, _| Ok(true))
|
||||
.map_err(|e| anyhow!("7z extraction failed: {e}"));
|
||||
@@ -330,7 +329,7 @@ fn find_ffmpeg_in(dir: &Path) -> Option<PathBuf> {
|
||||
}
|
||||
|
||||
fn extract_ffmpeg_from_zip(archive_path: &Path, dest: &Path) -> Result<()> {
|
||||
let file = std::fs::File::open(archive_path).context("opening zip archive")?;
|
||||
let file = File::open(archive_path).context("opening zip archive")?;
|
||||
let mut zip = zip::ZipArchive::new(file).context("open zip archive")?;
|
||||
for i in 0..zip.len() {
|
||||
let mut entry = zip.by_index(i)?;
|
||||
|
||||
Reference in New Issue
Block a user