From 4f25f7b3e6b1ea56431a8851c4be5f47447dcc78 Mon Sep 17 00:00:00 2001 From: Cory Snyder Date: Fri, 20 Sep 2024 05:01:13 -0400 Subject: [PATCH] Fix compatibility issues with alternative GHA cache implementation Fixes two compatibility issues with the alternative GHA cache server implementation: https://github.com/falcondev-oss/github-actions-cache-server 1. This implementation does not support redundant forward slashes in URL paths. The change allows magic-nix-cache to work properly regardless of whether ACTIONS_CACHE_URL ends in a forward slash or not. 2. The cache IDs returned by this implementation can be too big for an i32, so the representation of the CacheID type has been updated to an i64. Signed-off-by: Cory Snyder --- gha-cache/src/api.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gha-cache/src/api.rs b/gha-cache/src/api.rs index b7dc38f..1f0b545 100644 --- a/gha-cache/src/api.rs +++ b/gha-cache/src/api.rs @@ -116,7 +116,7 @@ pub struct FileAllocation(CacheId); /// The ID of a cache. #[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[serde(transparent)] -struct CacheId(pub i32); +struct CacheId(pub i64); /// An API error. #[derive(Debug, Clone)] @@ -543,10 +543,13 @@ impl Api { } fn construct_url(&self, resource: &str) -> String { - format!( - "{}/_apis/artifactcache/{}", - self.credentials.cache_url, resource - ) + let mut url = self.credentials.cache_url.clone(); + if !url.ends_with('/') { + url.push('/'); + } + url.push_str("_apis/artifactcache/"); + url.push_str(resource); + url } }