Skip to content

Commit

Permalink
fix(download): should not error when the model to be removed not exis…
Browse files Browse the repository at this point in the history
…ted (#3296)

* fix: should not be error if file not found when newly download model

* chore: only check sha256 when model exists
  • Loading branch information
zwpaper authored Oct 22, 2024
1 parent 096dd20 commit 681dc9d
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions crates/tabby-download/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Responsible for downloading ML models for use with tabby.
use std::fs;
use std::{fs, io};

use aim_downloader::{bar::WrappedBar, error::DownloadError, hash::HashChecker, https};
use anyhow::{bail, Result};
Expand Down Expand Up @@ -103,26 +103,35 @@ async fn download_model_impl(
return Ok(());
}

info!("Checking model integrity..");
if model_existed {
info!("Checking model integrity..");

let mut sha256_matched = true;
for (index, url) in urls.iter().enumerate() {
if HashChecker::check(partitioned_file_name!(index, urls.len()).as_str(), &url.1).is_err() {
sha256_matched = false;
break;
let mut sha256_matched = true;
for (index, url) in urls.iter().enumerate() {
if HashChecker::check(partitioned_file_name!(index, urls.len()).as_str(), &url.1)
.is_err()
{
sha256_matched = false;
break;
}
}
}

if sha256_matched {
return Ok(());
}
if sha256_matched {
return Ok(());
}

warn!(
"Checksum doesn't match for <{}/{}>, re-downloading...",
registry.name, name
);
warn!(
"Checksum doesn't match for <{}/{}>, re-downloading...",
registry.name, name
);
}

fs::remove_dir_all(registry.get_model_dir(name))?;
match fs::remove_dir_all(registry.get_model_dir(name)) {
Ok(_) => Ok(()),
// Ignore "Not Found" error, when newly download, the model directory may not exist
Err(ref e) if e.kind() == io::ErrorKind::NotFound => Ok(()),
Err(e) => Err(e),
}?;

// prepare for download
let dir = registry.get_model_store_dir(name);
Expand Down

0 comments on commit 681dc9d

Please sign in to comment.