This commit is contained in:
Ubuntu
2023-06-27 17:24:26 +00:00
parent 8b4b2d1830
commit e29dae044d
5 changed files with 229 additions and 85 deletions

View File

@ -378,6 +378,12 @@ impl Api {
let parallel_failures_semaphore = Arc::new(Semaphore::new(self.parallel_failures));
let filename = temp_filename();
// Create the file and set everything properly
tokio::fs::File::create(&filename)
.await?
.set_len(length as u64)
.await?;
let chunk_size = self.chunk_size;
for start in (0..length).step_by(chunk_size) {
let url = url.to_string();
@ -391,6 +397,7 @@ impl Api {
let parallel_failures_semaphore = parallel_failures_semaphore.clone();
let progress = progressbar.clone();
handles.push(tokio::spawn(async move {
println!("Start {start:?} - {stop:?}");
let mut chunk = Self::download_chunk(&client, &url, &filename, start, stop).await;
let mut i = 0;
if parallel_failures > 0 {
@ -440,7 +447,6 @@ impl Api {
let range = format!("bytes={start}-{stop}");
let mut file = tokio::fs::OpenOptions::new()
.write(true)
.create(true)
.open(filename)
.await?;
file.seek(SeekFrom::Start(start as u64)).await?;

View File

@ -53,7 +53,11 @@ impl Cache {
let commit_hash = std::fs::read_to_string(commit_path).ok()?;
let mut pointer_path = self.pointer_path(repo, &commit_hash);
pointer_path.push(filename);
Some(pointer_path)
if pointer_path.exists(){
Some(pointer_path)
}else{
None
}
}
/// Creates a reference in the cache directory that points branches to the correct
@ -146,7 +150,12 @@ impl Repo {
/// The normalized folder nameof the repo within the cache directory
pub fn folder_name(&self) -> String {
self.repo_id.replace('/', "--")
let prefix = match self.repo_type{
RepoType::Model => "models",
RepoType::Dataset => "datasets",
RepoType::Space => "spaces",
};
format!("{prefix}--{}", self.repo_id).replace('/', "--")
}
/// The revision