Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ use std::task::{ready, Poll};
use anyhow::Context as _;
use cargo_util::paths::{self, exclude_from_backups_and_indexing};
use flate2::read::GzDecoder;
use semver::VersionReq;
use serde::Deserialize;
use serde::Serialize;
use tar::Archive;
Expand Down Expand Up @@ -694,6 +695,10 @@ impl<'gctx> RegistrySource<'gctx> {
.open(&path)
.with_context(|| format!("failed to open `{}`", path.display()))?;

if let Err(e) = patch_extracted_package_if_needed(pkg, unpack_dir) {
tracing::warn!("error patching {pkg}: {e}");
}

let lock_meta = LockMetadata { v: 1 };
write!(ok, "{}", serde_json::to_string(&lock_meta).unwrap())?;

Expand Down Expand Up @@ -740,6 +745,28 @@ impl<'gctx> RegistrySource<'gctx> {
}
}

/// Workaround for <https://github.com/rust-lang/rust/issues/127343> in the `time` crate
fn patch_extracted_package_if_needed(pkg: PackageId, unpack_dir: &Path) -> CargoResult<()> {
if !pkg.source_id().is_crates_io()
|| pkg.name() != "time"
|| !VersionReq::parse("0.3.18,<0.3.35")
.unwrap()
.matches(pkg.version())
{
return Ok(());
}

let patch_path = unpack_dir.join("src/format_description/parse/mod.rs");
let source_code = std::fs::read_to_string(&patch_path)?;

let patched = source_code.replace(
"<Result<Box<_>, _>>",
"<Result<Box<[_ /*patched by Cargo*/ ]>, _>>",
);
std::fs::write(&patch_path, patched)?;
Ok(())
}

impl<'gctx> Source for RegistrySource<'gctx> {
fn query(
&mut self,
Expand Down