Initial stabilization #1

Merged
dzu merged 10 commits from stabilize-v1 into main 2026-02-20 16:23:43 +01:00
Showing only changes of commit c685a1db3e - Show all commits

fix: commit cache

Artem Diachenko 2026-02-20 09:35:58 +00:00

View file

@ -85,10 +85,14 @@ impl Client {
}
pub fn save_cache(&self, key: &CacheKey, cache: Vec<u8>) -> Result<()> {
let cache_id = self.reserve(key, cache.len()).context("reserving cache")?;
let cache_len = cache.len();
let cache_id = self.reserve(key, cache_len).context("reserving cache")?;
self.save(cache_id, cache).context("saving the cache")?;
self.commit_cache(cache_id, cache_len)
.context("committing the cache")?;
Ok(())
}
@ -169,6 +173,38 @@ impl Client {
Ok(())
}
fn commit_cache(&self, id: CacheId, cache_size: usize) -> Result<()> {
let uri = format!("{}_apis/artifactcache/caches/{}", self.base_url, id.0);
let request = Request::builder()
.uri(uri)
.method(Method::POST)
.body(
serde_json::json! {{
"size": cache_size,
}}
.to_string(),
)
.context("building the request")?;
let mut response = self
.http_client
.send(request)
.context("sending the request")?;
let status = response.status();
if status != StatusCode::OK {
let mut body = Vec::with_capacity(100);
response
.body_mut()
.read_to_end(&mut body)
.context("reading response body")?;
bail!(
"Failed reserving a cache (status {status}): {:?}",
String::from_utf8_lossy(&body)
);
}
Ok(())
}
pub fn load_cache(&self, key: &CacheKey) -> Result<Option<Box<[u8]>>> {
let Some(cache_location) = self.get_cache_entry(key).context("getting cache entry")? else {
// cache miss