Skip to content

Commit 0b74b97

Browse files
committed
also fix transform on fix save
1 parent ee400e2 commit 0b74b97

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

rs_lib/src/local.rs

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,11 @@ impl<TSys: LocalHttpCacheSys> LocalHttpCache<TSys> {
321321
}
322322
}
323323

324-
fn transform_content_on_copy_to_local(
324+
fn transform_content_on_copy_to_local<'a>(
325325
&self,
326326
url: &Url,
327-
content: Cow<'static, [u8]>,
328-
) -> Cow<'static, [u8]> {
327+
content: Cow<'a, [u8]>,
328+
) -> Cow<'a, [u8]> {
329329
let Some(jsr_url) = &self.jsr_registry_url else {
330330
return content;
331331
};
@@ -425,11 +425,13 @@ impl<TSys: LocalHttpCacheSys> HttpCache for LocalHttpCache<TSys> {
425425
let sub_path = url_to_local_sub_path(url, headers_content_type(&headers))?;
426426

427427
if !is_redirect {
428+
let content =
429+
self.transform_content_on_copy_to_local(url, Cow::Borrowed(content));
428430
// Cache content
429431
atomic_write_file_with_retries(
430432
self.env(),
431433
&sub_path.as_path_from_root(&self.path),
432-
content,
434+
&content,
433435
CACHE_PERM,
434436
)?;
435437
}
@@ -1258,24 +1260,47 @@ mod test {
12581260
#[test]
12591261
fn test_copy_version_metadata_file() {
12601262
let test_caches = TestCaches::new();
1261-
let metadata_url =
1262-
Url::parse("https://jsr.io/@david/dax/1.2.3_meta.json").unwrap();
12631263
let data =
12641264
r#"{ "moduleGraph2": "testing", "checksums": { "test": "test" } }"#;
1265-
test_caches
1266-
.global_cache
1267-
.set(&metadata_url, Default::default(), data.as_bytes())
1268-
.unwrap();
1269-
let key = test_caches
1270-
.local_cache
1271-
.cache_item_key(&metadata_url)
1272-
.unwrap();
1273-
let final_data = test_caches.local_cache.get(&key, None).unwrap().unwrap();
1274-
assert_eq!(
1275-
String::from_utf8(final_data.content.to_vec()).unwrap(),
1276-
// had the moduleGraph2 property stripped
1277-
r#"{"checksums":{"test":"test"},"lockfileChecksum":"dc108ae9ffb13086cb1551692960c21893991a7f0f9dc770814ff21522fd1d48"}"#
1278-
);
1265+
// has the moduleGraph2 property stripped
1266+
let expected_data = r#"{"checksums":{"test":"test"},"lockfileChecksum":"dc108ae9ffb13086cb1551692960c21893991a7f0f9dc770814ff21522fd1d48"}"#;
1267+
{
1268+
let metadata_url =
1269+
Url::parse("https://jsr.io/@david/dax/1.2.3_meta.json").unwrap();
1270+
test_caches
1271+
.global_cache
1272+
.set(&metadata_url, Default::default(), data.as_bytes())
1273+
.unwrap();
1274+
let key = test_caches
1275+
.local_cache
1276+
.cache_item_key(&metadata_url)
1277+
.unwrap();
1278+
let final_data =
1279+
test_caches.local_cache.get(&key, None).unwrap().unwrap();
1280+
assert_eq!(
1281+
String::from_utf8(final_data.content.to_vec()).unwrap(),
1282+
expected_data,
1283+
);
1284+
}
1285+
{
1286+
// now try just setting directly in the local cache
1287+
let metadata_url =
1288+
Url::parse("https://jsr.io/@david/dax/1.2.2_meta.json").unwrap();
1289+
test_caches
1290+
.local_cache
1291+
.set(&metadata_url, Default::default(), data.as_bytes())
1292+
.unwrap();
1293+
let key = test_caches
1294+
.local_cache
1295+
.cache_item_key(&metadata_url)
1296+
.unwrap();
1297+
let final_data =
1298+
test_caches.local_cache.get(&key, None).unwrap().unwrap();
1299+
assert_eq!(
1300+
String::from_utf8(final_data.content.to_vec()).unwrap(),
1301+
expected_data,
1302+
);
1303+
}
12791304
}
12801305

12811306
#[test]

0 commit comments

Comments
 (0)