diff options
author | Nicolas Patry <patry.nicolas@protonmail.com> | 2023-06-28 16:49:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-28 16:49:07 +0200 |
commit | 8b4b2d1830e6fb5aed2c410256bb4e7076e5007d (patch) | |
tree | 96b9d9fe52bf9f8241e2dae36b69d73509884785 /candle-hub/src/api.rs | |
parent | d461d9d751df67f262f108300dbc4e433d6062f5 (diff) | |
parent | cfdfc04d5cd2203060691cc787d060fb5a1380c6 (diff) | |
download | candle-8b4b2d1830e6fb5aed2c410256bb4e7076e5007d.tar.gz candle-8b4b2d1830e6fb5aed2c410256bb4e7076e5007d.tar.bz2 candle-8b4b2d1830e6fb5aed2c410256bb4e7076e5007d.zip |
Merge pull request #28 from LaurentMazare/fix_hub
Remove the unecessary file lock, attempt to rename before copying.
Diffstat (limited to 'candle-hub/src/api.rs')
-rw-r--r-- | candle-hub/src/api.rs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/candle-hub/src/api.rs b/candle-hub/src/api.rs index 9ea014ec..f4d9c1ec 100644 --- a/candle-hub/src/api.rs +++ b/candle-hub/src/api.rs @@ -1,5 +1,4 @@ use crate::{Cache, Repo}; -use fs2::FileExt; use indicatif::{ProgressBar, ProgressStyle}; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use reqwest::{ @@ -492,13 +491,6 @@ impl Api { let blob_path = self.cache.blob_path(repo, &metadata.etag); std::fs::create_dir_all(blob_path.parent().unwrap())?; - let file1 = std::fs::OpenOptions::new() - .read(true) - .write(true) - .create(true) - .open(&blob_path)?; - file1.lock_exclusive()?; - let progressbar = if self.progress { let progress = ProgressBar::new(metadata.size as u64); progress.set_style( @@ -522,7 +514,12 @@ impl Api { let tmp_filename = self .download_tempfile(&url, metadata.size, progressbar) .await?; - tokio::fs::copy(tmp_filename, &blob_path).await?; + + if tokio::fs::rename(&tmp_filename, &blob_path).await.is_err() { + // Renaming may fail if locations are different mount points + std::fs::File::create(&blob_path)?; + tokio::fs::copy(tmp_filename, &blob_path).await?; + } let mut pointer_path = self.cache.pointer_path(repo, &metadata.commit_hash); pointer_path.push(filename); |