This accidentally regressed in the previous caching PR for Cargo.
Invalid lines of JSON in the registry are intended to be skipped over,
but when skipping we forgot to update some indices which meant that all
future versions would fail to parse as well!
// interpretation of each line here and older cargo will simply
// ignore the new lines.
let line = &contents[start..end];
+ start = end + 1;
let summary = match IndexSummary::parse(line, source_id) {
Ok(summary) => summary,
Err(e) => {
let version = summary.summary.package_id().version().clone();
cache.versions.push((version.clone(), line));
ret.versions.insert(version, summary.into());
- start = end + 1;
}
if let Some(index_version) = index_version {
cache_bytes = Some(cache.serialize(index_version));
p.cargo("build --features bar/foo01").run();
p.cargo("build --features bar/another").run();
}
+
+#[test]
+fn ignore_invalid_json_lines() {
+ Package::new("foo", "0.1.0").publish();
+ Package::new("foo", "0.1.1")
+ .invalid_json(true)
+ .publish();
+ Package::new("foo", "0.2.0").publish();
+
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [project]
+ name = "a"
+ version = "0.5.0"
+ authors = []
+
+ [dependencies]
+ foo = '0.1.0'
+ foo02 = { version = '0.2.0', package = 'foo' }
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("build").run();
+}
use cargo::util::Sha256;
use flate2::write::GzEncoder;
use flate2::Compression;
-use git2;
-use hex;
use tar::{Builder, Header};
use url::Url;
features: HashMap<String, Vec<String>>,
local: bool,
alternative: bool,
+ invalid_json: bool,
}
#[derive(Clone)]
features: HashMap::new(),
local: false,
alternative: false,
+ invalid_json: false,
}
}
self
}
+ /// Causes the JSON line emitted in the index to be invalid, presumably
+ /// causing Cargo to skip over this version.
+ pub fn invalid_json(&mut self, invalid: bool) -> &mut Package {
+ self.invalid_json = invalid;
+ self
+ }
+
/// Creates the package and place it in the registry.
///
/// This does not actually use Cargo's publishing system, but instead
t!(t!(File::open(&self.archive_dst())).read_to_end(&mut c));
cksum(&c)
};
+ let name = if self.invalid_json {
+ serde_json::json!(1)
+ } else {
+ serde_json::json!(self.name)
+ };
let line = serde_json::json!({
- "name": self.name,
+ "name": name,
"vers": self.vers,
"deps": deps,
"cksum": cksum,