Skip to content

Commit c58bf1d

Browse files
committed
Check if a crate is library in add_package
1 parent 28bb113 commit c58bf1d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/db/add_package.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::io::BufReader;
88
use std::path::{Path, PathBuf};
99
use std::fs;
1010

11-
use cargo::core::Package;
11+
use cargo::core::{Package, TargetKind};
1212
use rustc_serialize::json::{Json, ToJson};
1313
use slug::slugify;
1414
use hyper::client::Client;
@@ -33,6 +33,10 @@ pub fn add_package_into_database(conn: &Connection,
3333
let rustdoc = get_rustdoc(&pkg).unwrap_or(None);
3434
let readme = get_readme(&pkg).unwrap_or(None);
3535
let (release_time, yanked, downloads) = try!(get_release_time_yanked_downloads(&pkg));
36+
let is_library = match pkg.targets()[0].kind() {
37+
&TargetKind::Lib(_) => true,
38+
_ => false,
39+
};
3640

3741
let release_id: i32 = {
3842
let rows = try!(conn.query("SELECT id FROM releases WHERE crate_id = $1 AND version = $2",
@@ -45,10 +49,12 @@ pub fn add_package_into_database(conn: &Connection,
4549
rustdoc_status, test_status, license, repository_url, \
4650
homepage_url, description, description_long, readme, \
4751
authors, keywords, have_examples, downloads, files, \
48-
doc_targets \
52+
doc_targets, is_library \
4953
) \
5054
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, \
51-
$11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21 ) \
55+
$11, $12, $13, $14, $15, $16, $17, $18, $19, \
56+
$20, $21, $22 \
57+
) \
5258
RETURNING id",
5359
&[&crate_id,
5460
&format!("{}", pkg.manifest().version()),
@@ -70,7 +76,8 @@ pub fn add_package_into_database(conn: &Connection,
7076
&res.have_examples,
7177
&downloads,
7278
&files,
73-
&doc_targets.to_json()]));
79+
&doc_targets.to_json(),
80+
&is_library]));
7481
// return id
7582
rows.get(0).get(0)
7683

@@ -80,7 +87,7 @@ pub fn add_package_into_database(conn: &Connection,
8087
$8, test_status = $9, license = $10, repository_url = $11, \
8188
homepage_url = $12, description = $13, description_long = $14, \
8289
readme = $15, authors = $16, keywords = $17, have_examples = $18, \
83-
downloads = $19, files = $20, doc_targets = $21 \
90+
downloads = $19, files = $20, doc_targets = $21, is_library = $22 \
8491
WHERE crate_id = $1 AND version = $2",
8592
&[&crate_id,
8693
&format!("{}", pkg.manifest().version()),
@@ -102,7 +109,8 @@ pub fn add_package_into_database(conn: &Connection,
102109
&res.have_examples,
103110
&downloads,
104111
&files,
105-
&doc_targets.to_json()]));
112+
&doc_targets.to_json(),
113+
&is_library]));
106114
rows.get(0).get(0)
107115
}
108116
};

src/db/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn create_tables(conn: &Connection) -> Result<(), Error> {
4545
dependencies JSON, \
4646
target_name VARCHAR(255), \
4747
yanked BOOL DEFAULT FALSE, \
48+
is_library BOOL DEFAULT TRUE, \
4849
build_status BOOL DEFAULT FALSE, \
4950
rustdoc_status BOOL DEFAULT FALSE, \
5051
test_status BOOL DEFAULT FALSE, \

0 commit comments

Comments
 (0)