From 8e0609006bca799426cf6e68911e5b292d8fcb70 Mon Sep 17 00:00:00 2001 From: Adinata Wijaya Date: Wed, 4 Sep 2024 13:48:22 +0200 Subject: [PATCH] fix rename temp file to cache file --- .github/workflows/release.yml | 2 +- Cargo.toml | 2 +- README.md | 4 ++++ src/repo_tools/mod.rs | 20 ++++++++++++-------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3daceaa..5e474b9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@master - name: Compile and release - uses: rust-build/rust-build.action@v1.4.0 + uses: rust-build/rust-build.action@v1.75.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/Cargo.toml b/Cargo.toml index b1b545b..43136b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lfspull" -version = "0.3.0" +version = "0.3.1" edition = "2021" license = "MIT" authors = ["Volume Graphics GmbH"] diff --git a/README.md b/README.md index a6d4ec8..1f5737c 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ Please see our docs.rs for example code and the gherkin tests for how to check t ## Changelog +### 0.3.1 + +- fix bug when trying to rename temp file to cache file, but cache file is already created and locked by other parallel job + ### 0.3.0 - use stream_bytes to download object directly into a temporary files and avoid 'memory allocation of x bytes failed' \ No newline at end of file diff --git a/src/repo_tools/mod.rs b/src/repo_tools/mod.rs index 3cc10aa..196210b 100644 --- a/src/repo_tools/mod.rs +++ b/src/repo_tools/mod.rs @@ -120,14 +120,18 @@ async fn get_file_cached>( let temp_file = primitives::download_file(metadata, &repo_url, access_token, randomizer_bytes).await?; - fs::rename(&temp_file.path(), cache_file.as_path()) - .map_err(|e| { - LFSError::FatFileIOError(FatIOError::from_std_io_err( - e, - temp_file.path().to_path_buf(), - )) - }) - .await?; + if cache_file.is_file() { + debug!("cache file {:?} is already written from other process", &cache_file); + } else { + fs::rename(&temp_file.path(), cache_file.as_path()) + .map_err(|e| { + LFSError::FatFileIOError(FatIOError::from_std_io_err( + e, + temp_file.path().to_path_buf(), + )) + }) + .await?; + } Ok((cache_file, FilePullMode::DownloadedFromRemote)) }