Skip to content

Commit

Permalink
Fix tool storage still being case sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Apr 2, 2024
1 parent d1793c2 commit 6ecef4f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## `0.0.2` - April 2nd, 2024

### Breaking Changes

Tools are now stored in a case-insensitive manner to prevent unnecessary downloading and linking of duplicate tool specifications. This means that tools in manifests that are not all lowercase may no longer work on case-sensitive filesystems. To fix this, remove the `~/.rokit/tool-storage` directory, and Rokit will re-download and install tools next time you run `rokit install`.

### Fixed

- Fixed tool aliases being case-sensitive
Expand Down
19 changes: 14 additions & 5 deletions lib/storage/tool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,24 @@ pub struct ToolStorage {

impl ToolStorage {
fn tool_paths(&self, spec: &ToolSpec) -> (PathBuf, PathBuf) {
// NOTE: We use uncased strings for the tool author and name
// to ensure that the tool paths are always case-insensitive
let tool_dir = self
.tools_dir
.join(spec.author())
.join(spec.name())
.join(spec.version().to_string());
let tool_file = tool_dir.join(format!("{}{EXE_SUFFIX}", spec.name()));
.join(spec.id.author.uncased_str())
.join(spec.id.name.uncased_str())
.join(spec.version.to_string());

let tool_file_name = format!("{}{EXE_SUFFIX}", spec.id.name.uncased_str());
let tool_file = tool_dir.join(tool_file_name);

(tool_dir, tool_file)
}

fn alias_path(&self, alias: &ToolAlias) -> PathBuf {
self.aliases_dir.join(alias.name.uncased_str())
}

fn rokit_path(&self) -> PathBuf {
self.aliases_dir.join(format!("rokit{EXE_SUFFIX}"))
}
Expand Down Expand Up @@ -108,7 +117,7 @@ impl ToolStorage {
- If the link could not be written.
*/
pub async fn create_tool_link(&self, alias: &ToolAlias) -> RokitResult<()> {
let path = self.aliases_dir.join(alias.name());
let path = self.alias_path(alias);
if cfg!(unix) && !self.no_symlinks {
let rokit_path = self.rokit_path();
write_executable_link(path, &rokit_path).await?;
Expand Down
6 changes: 3 additions & 3 deletions lib/tool/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub enum ToolAliasParseError {
/**
A tool alias, which is a simple string identifier for a tool.
Tool aliases are not case sensitive for comparisons,
but keep their original casing for display purposes.
Tool aliases are not case sensitive for comparisons, but keep
their original casing for display and serialization purposes.
See [`CaseInsensitiveString`] for more information.
Used in:
Expand All @@ -36,7 +36,7 @@ pub enum ToolAliasParseError {
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, DeserializeFromStr, SerializeDisplay,
)]
pub struct ToolAlias {
name: CaseInsensitiveString,
pub(crate) name: CaseInsensitiveString,
}

impl ToolAlias {
Expand Down
10 changes: 5 additions & 5 deletions lib/tool/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub enum ToolIdParseError {
/**
A tool identifier, which includes the author and name of a tool.
Tool identifiers are not case sensitive for comparisons,
but keep their original casing for display purposes.
Tool identifiers are not case sensitive for comparisons, but keep
their original casing for display and serialization purposes.
See [`CaseInsensitiveString`] for more information.
Also includes the provider of the artifact, which by default is `GitHub`.
Expand All @@ -38,9 +38,9 @@ pub enum ToolIdParseError {
*/
#[derive(Debug, Clone, PartialEq, Eq, Hash, DeserializeFromStr, SerializeDisplay)]
pub struct ToolId {
provider: ArtifactProvider,
author: CaseInsensitiveString,
name: CaseInsensitiveString,
pub(crate) provider: ArtifactProvider,
pub(crate) author: CaseInsensitiveString,
pub(crate) name: CaseInsensitiveString,
}

impl ToolId {
Expand Down
4 changes: 2 additions & 2 deletions lib/tool/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub enum ToolSpecParseError {
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, DeserializeFromStr, SerializeDisplay,
)]
pub struct ToolSpec {
pub(super) id: ToolId,
pub(super) version: Version,
pub(crate) id: ToolId,
pub(crate) version: Version,
}

impl ToolSpec {
Expand Down

0 comments on commit 6ecef4f

Please sign in to comment.