-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make PackageCache multi-process safe (#837)
- Loading branch information
1 parent
c02c992
commit 3c4d098
Showing
41 changed files
with
965 additions
and
579 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use rattler_conda_types::package::ArchiveIdentifier; | ||
use rattler_conda_types::PackageRecord; | ||
use rattler_digest::Sha256Hash; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
/// Provides a unique identifier for packages in the cache. | ||
/// TODO: This could not be unique over multiple subdir. How to handle? | ||
/// TODO: Wouldn't it be better to cache based on hashes? | ||
#[derive(Debug, Hash, Clone, Eq, PartialEq)] | ||
pub struct CacheKey { | ||
name: String, | ||
version: String, | ||
build_string: String, | ||
sha256: Option<Sha256Hash>, | ||
} | ||
|
||
impl CacheKey { | ||
/// Adds a sha256 hash of the archive. | ||
pub fn with_sha256(mut self, sha256: Sha256Hash) -> Self { | ||
self.sha256 = Some(sha256); | ||
self | ||
} | ||
|
||
/// Potentially adds a sha256 hash of the archive. | ||
pub fn with_opt_sha256(mut self, sha256: Option<Sha256Hash>) -> Self { | ||
self.sha256 = sha256; | ||
self | ||
} | ||
} | ||
|
||
impl CacheKey { | ||
/// Return the sha256 hash of the package if it is known. | ||
pub fn sha256(&self) -> Option<Sha256Hash> { | ||
self.sha256 | ||
} | ||
} | ||
|
||
impl From<ArchiveIdentifier> for CacheKey { | ||
fn from(pkg: ArchiveIdentifier) -> Self { | ||
CacheKey { | ||
name: pkg.name, | ||
version: pkg.version, | ||
build_string: pkg.build_string, | ||
sha256: None, | ||
} | ||
} | ||
} | ||
|
||
impl From<&PackageRecord> for CacheKey { | ||
fn from(record: &PackageRecord) -> Self { | ||
Self { | ||
name: record.name.as_normalized().to_string(), | ||
version: record.version.to_string(), | ||
build_string: record.build.clone(), | ||
sha256: record.sha256, | ||
} | ||
} | ||
} | ||
|
||
impl Display for CacheKey { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}-{}-{}", &self.name, &self.version, &self.build_string) | ||
} | ||
} |
Oops, something went wrong.