Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7d2abf2
Add PackageCacheLayer and PackageCacheLayerError
kelvinou01 Dec 23, 2024
7aad0e3
Formatting and stuff
kelvinou01 Dec 23, 2024
d2fe3f5
Clippy
kelvinou01 Dec 23, 2024
9f97ec2
Merge branch 'main' of https://github.com/conda/rattler into feat/lay…
kelvinou01 Mar 8, 2025
1590382
Fix compile error
kelvinou01 Mar 8, 2025
868ab81
Fix tests for windows
kelvinou01 Mar 8, 2025
7f248e3
cargo fmt
kelvinou01 Mar 8, 2025
82023e2
Add comments
kelvinou01 Mar 8, 2025
cec3436
Add fixes
kelvinou01 Mar 11, 2025
b987982
Merge branch 'main' of https://github.com/conda/rattler into feat/lay…
kelvinou01 Mar 12, 2025
57483e8
Merge branch 'main' into feat/layered-package-cache
kelvinou01 Mar 18, 2025
6372fdd
Set link options in installer
kelvinou01 Mar 23, 2025
db11a22
Merge branch 'main' into feat/layered-package-cache
kelvinou01 Mar 23, 2025
c2a825d
Merge branch 'main' into main
kelvinou01 Mar 26, 2025
81cf618
Merge branch 'main' of https://github.com/conda/rattler
kelvinou01 Mar 30, 2025
0dc3594
Merge branch 'main' of https://github.com/conda/rattler
kelvinou01 Apr 1, 2025
f182867
Merge https://github.com/kelvinou01/rattler
kelvinou01 Apr 1, 2025
6527172
Merge branch 'main' of github.com:kelvinou01/rattler into feat/layere…
Jul 23, 2025
732dd90
Merge branch 'main' of github.com:conda/rattler
Jul 23, 2025
37d2aa8
Merge branch 'main' of github.com:kelvinou01/rattler into feat/layere…
Jul 24, 2025
65e1f72
Format
Jul 24, 2025
1675473
Merge branch 'main' into feat/layered-package-cache
kelvinou01 Jul 24, 2025
5739490
Fix
Jul 24, 2025
73ab6a8
Merge branch 'feat/layered-package-cache' of github.com:kelvinou01/ra…
Jul 24, 2025
6b9eeeb
Cargo clippy
Jul 24, 2025
435fbf1
Merge branch 'main' into feat/layered-package-cache
kelvinou01 Jul 24, 2025
12656f1
Merge branch 'main' into feat/layered-package-cache
kelvinou01 Jul 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions crates/rattler_cache/src/package_cache/cache_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use fs4::fs_std::FileExt;
use parking_lot::Mutex;
use rattler_digest::Sha256Hash;

use crate::package_cache::PackageCacheError;
use crate::package_cache::PackageCacheLayerError;

/// A lock on the cache entry. As long as this lock is held, no other process is
/// allowed to modify the cache entry. This however, does not guarantee that the
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Drop for CacheRwLock {
}

impl CacheRwLock {
pub async fn acquire_read(path: &Path) -> Result<Self, PackageCacheError> {
pub async fn acquire_read(path: &Path) -> Result<Self, PackageCacheLayerError> {
let lock_file_path = path.to_path_buf();

let acquire_lock_fut = simple_spawn_blocking::tokio::run_blocking_task(move || {
Expand All @@ -71,7 +71,7 @@ impl CacheRwLock {
.write(true)
.open(&lock_file_path)
.map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
format!(
"failed to open cache lock for reading: '{}'",
lock_file_path.display()
Expand All @@ -81,7 +81,7 @@ impl CacheRwLock {
})?;

fs4::fs_std::FileExt::lock_shared(&file).map_err(move |e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
format!(
"failed to acquire read lock on cache lock file: '{}'",
lock_file_path.display()
Expand All @@ -108,7 +108,7 @@ impl CacheRwLock {
}

impl CacheRwLock {
pub async fn acquire_write(path: &Path) -> Result<Self, PackageCacheError> {
pub async fn acquire_write(path: &Path) -> Result<Self, PackageCacheLayerError> {
let lock_file_path = path.to_path_buf();
let acquire_lock_fut = simple_spawn_blocking::tokio::run_blocking_task(move || {
let file = std::fs::OpenOptions::new()
Expand All @@ -118,7 +118,7 @@ impl CacheRwLock {
.read(true)
.open(&lock_file_path)
.map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
format!(
"failed to open cache lock for writing: '{}",
lock_file_path.display()
Expand All @@ -128,7 +128,7 @@ impl CacheRwLock {
})?;

file.lock_exclusive().map_err(move |e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
format!(
"failed to acquire write lock on cache lock file: '{}'",
lock_file_path.display()
Expand Down Expand Up @@ -159,15 +159,15 @@ impl CacheRwLock {
&mut self,
revision: u64,
sha256: Option<&Sha256Hash>,
) -> Result<(), PackageCacheError> {
) -> Result<(), PackageCacheLayerError> {
let file = self.file.clone();
let sha256 = sha256.cloned();
simple_spawn_blocking::tokio::run_blocking_task(move || {
let mut file = file.lock();

// Ensure we write from the start of the file
file.rewind().map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
"failed to rewind cache lock for reading revision".to_string(),
e,
)
Expand All @@ -176,7 +176,7 @@ impl CacheRwLock {
// Write the bytes of the revision
let revision_bytes = revision.to_be_bytes();
file.write_all(&revision_bytes).map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
"failed to write revision from cache lock".to_string(),
e,
)
Expand All @@ -187,7 +187,7 @@ impl CacheRwLock {
let len = sha.len();
let sha = &sha[..];
file.write_all(sha).map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
"failed to write sha256 from cache lock".to_string(),
e,
)
Expand All @@ -199,7 +199,7 @@ impl CacheRwLock {

// Ensure all bytes are written to disk
file.flush().map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
"failed to flush cache lock after writing revision".to_string(),
e,
)
Expand All @@ -208,7 +208,7 @@ impl CacheRwLock {
// Update the length of the file
let file_length = revision_bytes.len() + sha_bytes;
file.set_len(file_length as u64).map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
"failed to truncate cache lock after writing revision".to_string(),
e,
)
Expand All @@ -222,10 +222,10 @@ impl CacheRwLock {

impl CacheRwLock {
/// Reads the revision from the cache lock file.
pub fn read_revision(&mut self) -> Result<u64, PackageCacheError> {
pub fn read_revision(&mut self) -> Result<u64, PackageCacheLayerError> {
let mut file = self.file.lock();
file.rewind().map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
"failed to rewind cache lock for reading revision".to_string(),
e,
)
Expand All @@ -237,7 +237,7 @@ impl CacheRwLock {
return Ok(0);
}
Err(e) => {
return Err(PackageCacheError::LockError(
return Err(PackageCacheLayerError::LockError(
"failed to read revision from cache lock".to_string(),
e,
));
Expand All @@ -247,27 +247,30 @@ impl CacheRwLock {
}

/// Reads the sha256 hash from the cache lock file.
pub fn read_sha256(&mut self) -> Result<Option<Sha256Hash>, PackageCacheError> {
pub fn read_sha256(&mut self) -> Result<Option<Sha256Hash>, PackageCacheLayerError> {
const SHA256_LEN: usize = 32;
const REVISION_LEN: u64 = 8;
let mut file = self.file.lock();
file.rewind().map_err(|e| {
PackageCacheError::LockError(
PackageCacheLayerError::LockError(
"failed to rewind cache lock for reading sha256".to_string(),
e,
)
})?;
let mut buf = [0; SHA256_LEN];
let _ = file.seek(SeekFrom::Start(REVISION_LEN)).map_err(|e| {
PackageCacheError::LockError("failed to seek to sha256 in cache lock".to_string(), e)
PackageCacheLayerError::LockError(
"failed to seek to sha256 in cache lock".to_string(),
e,
)
})?;
match file.read_exact(&mut buf) {
Ok(_) => {}
Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => {
return Ok(None);
}
Err(e) => {
return Err(PackageCacheError::LockError(
return Err(PackageCacheLayerError::LockError(
"failed to read sha256 from cache lock".to_string(),
e,
));
Expand Down
Loading