Skip to content

Commit 8cd6725

Browse files
committed
Try to read package.metadata from Cargo.toml.orig first
1 parent 19f5839 commit 8cd6725

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/db/add_package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn add_package_into_database(conn: &Connection,
3939
&TargetKind::Lib(_) => true,
4040
_ => false,
4141
};
42-
let metadata = Metadata::from_package(pkg);
42+
let metadata = Metadata::from_package(pkg)?;
4343

4444
let release_id: i32 = {
4545
let rows = try!(conn.query("SELECT id FROM releases WHERE crate_id = $1 AND version = $2",

src/docbuilder/metadata.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use std::path::Path;
33
use cargo::core::Package;
44
use toml::Value;
5+
use error::Result;
56

67

78
/// Metadata for custom builds
@@ -55,8 +56,15 @@ pub struct Metadata {
5556

5657

5758
impl Metadata {
58-
pub fn from_package(pkg: &Package) -> Metadata {
59-
Metadata::from_manifest(pkg.manifest_path())
59+
pub fn from_package(pkg: &Package) -> Result<Metadata> {
60+
let src_path = pkg.manifest_path().parent().ok_or("Source path not available")?;
61+
for c in ["Cargo.toml.orig", "Cargo.toml"].iter() {
62+
let manifest_path = src_path.clone().join(c);
63+
if manifest_path.exists() {
64+
return Ok(Metadata::from_manifest(manifest_path));
65+
}
66+
}
67+
Err("Manifest not found".into())
6068
}
6169

6270
pub fn from_manifest<P: AsRef<Path>>(path: P) -> Metadata {

src/utils/build_doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> CargoR
4444
let current_dir = try!(env::current_dir());
4545
let target_dir = PathBuf::from(current_dir).join("cratesfyi");
4646

47-
let metadata = Metadata::from_package(&pkg);
47+
let metadata = Metadata::from_package(&pkg).map_err(|e| human(e.description()))?;
4848

4949
let opts = ops::CompileOptions {
5050
config: &config,

0 commit comments

Comments
 (0)