Skip to content

Commit

Permalink
fix rename temp file to cache file
Browse files Browse the repository at this point in the history
  • Loading branch information
Adinata Wijaya committed Sep 4, 2024
1 parent 614c12e commit 8e06090
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lfspull"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
license = "MIT"
authors = ["Volume Graphics GmbH"]
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
20 changes: 12 additions & 8 deletions src/repo_tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,18 @@ async fn get_file_cached<P: AsRef<Path>>(

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))
}
Expand Down

0 comments on commit 8e06090

Please sign in to comment.