Skip to content

Commit f29b562

Browse files
committed
Revert "Remove unused code (#558)"
This reverts commit 3809f94. This caused all builds to fail in the last step when copying documentation into the database.
1 parent 3809f94 commit f29b562

18 files changed

+127
-67
lines changed

src/bin/cratesfyi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub fn main() {
239239
let mut count = 1;
240240
let mut total = 0;
241241
while count != 0 {
242-
count = db::move_to_s3(&conn, 5_000).expect("Failed to upload batch to S3");
242+
count = db::file::move_to_s3(&conn, 5_000).expect("Failed to upload batch to S3");
243243
total += count;
244244
eprintln!(
245245
"moved {} rows to s3 in this batch, total moved so far: {}",

src/db/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn get_file_list_from_dir<P: AsRef<Path>>(path: P,
4242
}
4343

4444

45-
fn get_file_list<P: AsRef<Path>>(path: P) -> Result<Vec<PathBuf>> {
45+
pub fn get_file_list<P: AsRef<Path>>(path: P) -> Result<Vec<PathBuf>> {
4646
let path = path.as_ref();
4747
let mut files = Vec::new();
4848

src/db/migrate.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::borrow::Cow;
1010
#[derive(Copy, Clone)]
1111
enum ApplyMode {
1212
Permanent,
13-
#[cfg(test)]
1413
Temporary,
1514
}
1615

@@ -23,7 +22,6 @@ impl MigrationContext {
2322
fn format_query<'a>(&self, query: &'a str) -> Cow<'a, str> {
2423
match self.apply_mode {
2524
ApplyMode::Permanent => Cow::Borrowed(query),
26-
#[cfg(test)]
2725
ApplyMode::Temporary => {
2826
Cow::Owned(query.replace("CREATE TABLE", "CREATE TEMPORARY TABLE"))
2927
}
@@ -75,7 +73,6 @@ pub fn migrate(version: Option<Version>, conn: &Connection) -> CratesfyiResult<(
7573
migrate_inner(version, conn, ApplyMode::Permanent)
7674
}
7775

78-
#[cfg(test)]
7976
pub fn migrate_temporary(version: Option<Version>, conn: &Connection) -> CratesfyiResult<()> {
8077
migrate_inner(version, conn, ApplyMode::Temporary)
8178
}

src/db/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
pub(crate) use self::add_package::add_package_into_database;
44
pub(crate) use self::add_package::add_build_into_database;
55
pub(crate) use self::add_package::CratesIoData;
6-
pub use self::file::{add_path_into_database, move_to_s3};
7-
pub use self::migrate::migrate;
8-
#[cfg(test)]
9-
pub(crate) use self::migrate::migrate_temporary;
6+
pub use self::file::add_path_into_database;
7+
pub use self::migrate::{migrate, migrate_temporary};
108
pub use self::delete_crate::delete_crate;
119

1210
use postgres::{Connection, TlsMode};
@@ -16,7 +14,7 @@ use r2d2;
1614
use r2d2_postgres;
1715

1816
mod add_package;
19-
pub(crate) mod file;
17+
pub mod file;
2018
mod migrate;
2119
mod delete_crate;
2220
pub mod blacklist;
@@ -31,7 +29,7 @@ pub fn connect_db() -> Result<Connection, Error> {
3129
}
3230

3331

34-
pub(crate) fn create_pool() -> r2d2::Pool<r2d2_postgres::PostgresConnectionManager> {
32+
pub fn create_pool() -> r2d2::Pool<r2d2_postgres::PostgresConnectionManager> {
3533
let db_url = env::var("CRATESFYI_DATABASE_URL")
3634
.expect("CRATESFYI_DATABASE_URL environment variable is not exists");
3735
let manager = r2d2_postgres::PostgresConnectionManager::new(&db_url[..],

src/docbuilder/metadata.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use failure::err_msg;
2222
/// default-target = "x86_64-unknown-linux-gnu"
2323
/// rustc-args = [ "--example-rustc-arg" ]
2424
/// rustdoc-args = [ "--example-rustdoc-arg" ]
25+
/// dependencies = [ "example-system-dependency" ]
2526
/// ```
2627
///
2728
/// You can define one or more fields in your `Cargo.toml`.
@@ -48,6 +49,11 @@ pub struct Metadata {
4849

4950
/// List of command line arguments for `rustdoc`.
5051
pub rustdoc_args: Option<Vec<String>>,
52+
53+
/// System dependencies.
54+
///
55+
/// Docs.rs is running on a Debian jessie.
56+
pub dependencies: Option<Vec<String>>,
5157
}
5258

5359

@@ -63,7 +69,7 @@ impl Metadata {
6369
Err(err_msg("Manifest not found"))
6470
}
6571

66-
fn from_manifest<P: AsRef<Path>>(path: P) -> Metadata {
72+
pub fn from_manifest<P: AsRef<Path>>(path: P) -> Metadata {
6773
use std::fs::File;
6874
use std::io::Read;
6975
let mut f = match File::open(path) {
@@ -87,6 +93,7 @@ impl Metadata {
8793
default_target: None,
8894
rustc_args: None,
8995
rustdoc_args: None,
96+
dependencies: None,
9097
}
9198
}
9299

@@ -115,6 +122,8 @@ impl Metadata {
115122
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
116123
metadata.rustdoc_args = table.get("rustdoc-args").and_then(|f| f.as_array())
117124
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
125+
metadata.dependencies = table.get("dependencies").and_then(|f| f.as_array())
126+
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
118127
}
119128

120129
metadata
@@ -142,6 +151,7 @@ mod test {
142151
default-target = "x86_64-unknown-linux-gnu"
143152
rustc-args = [ "--example-rustc-arg" ]
144153
rustdoc-args = [ "--example-rustdoc-arg" ]
154+
dependencies = [ "example-system-dependency" ]
145155
"#;
146156

147157
let metadata = Metadata::from_str(manifest);
@@ -166,5 +176,9 @@ mod test {
166176
let rustdoc_args = metadata.rustdoc_args.unwrap();
167177
assert_eq!(rustdoc_args.len(), 1);
168178
assert_eq!(rustdoc_args[0], "--example-rustdoc-arg".to_owned());
179+
180+
let dependencies = metadata.dependencies.unwrap();
181+
assert_eq!(dependencies.len(), 1);
182+
assert_eq!(dependencies[0], "example-system-dependency".to_owned());
169183
}
170184
}

src/docbuilder/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
pub(crate) mod options;
3-
mod metadata;
2+
pub mod options;
3+
pub mod metadata;
44
mod limits;
55
mod rustwide_builder;
66
mod crates;
@@ -9,7 +9,6 @@ mod queue;
99
pub use self::rustwide_builder::RustwideBuilder;
1010
pub(crate) use self::rustwide_builder::BuildResult;
1111
pub(crate) use self::limits::Limits;
12-
pub(self) use self::metadata::Metadata;
1312

1413

1514
use std::fs;

src/docbuilder/rustwide_builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::borrow::Cow;
1616
use std::collections::HashSet;
1717
use std::path::Path;
1818
use utils::{copy_doc_dir, parse_rustc_version, CargoMetadata};
19-
use super::Metadata;
19+
use Metadata;
2020

2121
const USER_AGENT: &str = "docs.rs builder (https://github.com/rust-lang/docs.rs)";
2222
const DEFAULT_RUSTWIDE_WORKSPACE: &str = ".rustwide";
@@ -522,7 +522,8 @@ impl RustwideBuilder {
522522
}
523523

524524
info!("{} {}", source.display(), dest.display());
525-
copy_doc_dir(source, dest)
525+
copy_doc_dir(source, dest, self.rustc_version.trim())?;
526+
Ok(())
526527
}
527528

528529
fn upload_docs(

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
33
use std::result::Result as StdResult;
44

5-
pub(crate) use failure::Error;
5+
pub use failure::{Error, ResultExt};
66

77
pub type Result<T> = StdResult<T, Error>;

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ extern crate once_cell;
4747
pub use self::docbuilder::RustwideBuilder;
4848
pub use self::docbuilder::DocBuilder;
4949
pub use self::docbuilder::options::DocBuilderOptions;
50+
pub use self::docbuilder::metadata::Metadata;
5051
pub use self::web::Server;
5152

52-
mod error;
53+
pub mod error;
5354
pub mod db;
5455
pub mod utils;
5556
mod docbuilder;

src/utils/copy.rs

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,44 @@ use error::Result;
88

99
use regex::Regex;
1010

11+
12+
/// Copies files from source directory to destination directory.
13+
pub fn copy_dir<P: AsRef<Path>>(source: P, destination: P) -> Result<()> {
14+
copy_files_and_handle_html(source.as_ref().to_path_buf(),
15+
destination.as_ref().to_path_buf(),
16+
false,
17+
"")
18+
}
19+
20+
1121
/// Copies documentation from a crate's target directory to destination.
1222
///
1323
/// Target directory must have doc directory.
1424
///
15-
/// This function is designed to avoid file duplications.
16-
pub fn copy_doc_dir<P: AsRef<Path>>(target: P, destination: P) -> Result<()> {
25+
/// This function is designed to avoid file duplications. It is using rustc version string
26+
/// to rename common files (css files, jquery.js, playpen.js, main.js etc.) in a standard rustdoc.
27+
pub fn copy_doc_dir<P: AsRef<Path>>(target: P,
28+
destination: P,
29+
rustc_version: &str)
30+
-> Result<()> {
1731
let source = PathBuf::from(target.as_ref()).join("doc");
18-
let destination = destination.as_ref().to_path_buf();
32+
copy_files_and_handle_html(source,
33+
destination.as_ref().to_path_buf(),
34+
true,
35+
rustc_version)
36+
}
1937

20-
// Make sure destination directory exists
38+
39+
fn copy_files_and_handle_html(source: PathBuf,
40+
destination: PathBuf,
41+
handle_html: bool,
42+
rustc_version: &str)
43+
-> Result<()> {
44+
45+
// FIXME: handle_html is useless since we started using --resource-suffix
46+
// argument with rustdoc
47+
48+
// Make sure destination directory is exists
2149
if !destination.exists() {
2250
fs::create_dir_all(&destination)?;
2351
}
@@ -37,8 +65,11 @@ pub fn copy_doc_dir<P: AsRef<Path>>(target: P, destination: P) -> Result<()> {
3765

3866
if metadata.is_dir() {
3967
fs::create_dir_all(&destination_full_path)?;
40-
copy_doc_dir(file.path(), destination_full_path)?
41-
} else if dup_regex.is_match(&file.file_name().into_string().unwrap()[..]) {
68+
copy_files_and_handle_html(file.path(),
69+
destination_full_path,
70+
handle_html,
71+
&rustc_version)?
72+
} else if handle_html && dup_regex.is_match(&file.file_name().into_string().unwrap()[..]) {
4273
continue;
4374
} else {
4475
fs::copy(&file.path(), &destination_full_path)?;
@@ -54,21 +85,19 @@ pub fn copy_doc_dir<P: AsRef<Path>>(target: P, destination: P) -> Result<()> {
5485
mod test {
5586
extern crate env_logger;
5687
use std::fs;
88+
use std::path::Path;
5789
use super::*;
5890

5991
#[test]
60-
fn test_copy_doc_dir() {
61-
let source = tempdir::TempDir::new("cratesfyi-src").unwrap();
62-
let destination = tempdir::TempDir::new("cratesfyi-dst").unwrap();
63-
let doc = source.path().join("doc");
64-
fs::create_dir(&doc).unwrap();
65-
66-
fs::write(doc.join("index.html"), "<html>spooky</html>").unwrap();
67-
fs::write(doc.join("index.txt"), "spooky").unwrap();
92+
#[ignore]
93+
fn test_copy_dir() {
94+
let destination = tempdir::TempDir::new("cratesfyi").unwrap();
6895

6996
// lets try to copy a src directory to tempdir
70-
copy_doc_dir(source.path(), destination.path()).unwrap();
71-
assert!(destination.path().join("index.html").exists());
72-
assert!(!destination.path().join("index.txt").exists());
97+
let res = copy_dir(Path::new("src"), destination.path());
98+
// remove temp dir
99+
fs::remove_dir_all(destination.path()).unwrap();
100+
101+
assert!(res.is_ok());
73102
}
74103
}

src/utils/github_updater.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use failure::err_msg;
99
/// Fields we need use in cratesfyi
1010
#[derive(Debug)]
1111
struct GitHubFields {
12-
description: String,
13-
stars: i64,
14-
forks: i64,
15-
issues: i64,
16-
last_commit: time::Timespec,
12+
pub description: String,
13+
pub stars: i64,
14+
pub forks: i64,
15+
pub issues: i64,
16+
pub last_commit: time::Timespec,
1717
}
1818

1919

src/utils/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! Various utilities for cratesfyi
22
33

4-
pub(crate) use self::copy::copy_doc_dir;
4+
pub use self::copy::{copy_dir, copy_doc_dir};
55
pub use self::github_updater::github_updater;
66
pub use self::release_activity_updater::update_release_activity;
77
pub use self::daemon::start_daemon;
8-
pub(crate) use self::rustc_version::parse_rustc_version;
9-
pub(crate) use self::html::extract_head_and_body;
8+
pub use self::rustc_version::{parse_rustc_version, get_current_versions, command_result};
9+
pub use self::html::extract_head_and_body;
1010
pub use self::queue::add_crate_to_queue;
1111
pub(crate) use self::cargo_metadata::{CargoMetadata, Package as MetadataPackage};
1212

src/utils/rustc_version.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
use std::process::{Command, Output};
23
use regex::Regex;
34
use error::Result;
45
use failure::err_msg;
@@ -17,6 +18,26 @@ pub fn parse_rustc_version<S: AsRef<str>>(version: S) -> Result<String> {
1718
captures.get(2).unwrap().as_str()))
1819
}
1920

21+
22+
/// Returns current version of rustc and cratesfyi
23+
pub fn get_current_versions() -> Result<(String, String)> {
24+
let rustc_version = command_result(Command::new("rustc").arg("--version").output()?)?;
25+
let cratesfyi_version = command_result(Command::new("rustc").arg("--version").output()?)?;
26+
27+
Ok((rustc_version, cratesfyi_version))
28+
}
29+
30+
31+
pub fn command_result(output: Output) -> Result<String> {
32+
let mut command_out = String::from_utf8_lossy(&output.stdout).into_owned();
33+
command_out.push_str(&String::from_utf8_lossy(&output.stderr).into_owned()[..]);
34+
match output.status.success() {
35+
true => Ok(command_out),
36+
false => Err(err_msg(command_out)),
37+
}
38+
}
39+
40+
2041
#[test]
2142
fn test_parse_rustc_version() {
2243
assert_eq!(parse_rustc_version("rustc 1.10.0-nightly (57ef01513 2016-05-23)").unwrap(),

src/web/crate_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct CrateDetails {
4343
github_stars: Option<i32>,
4444
github_forks: Option<i32>,
4545
github_issues: Option<i32>,
46-
pub(crate) metadata: MetaData,
46+
pub metadata: MetaData,
4747
is_library: bool,
4848
doc_targets: Option<Json>,
4949
license: Option<String>,

0 commit comments

Comments
 (0)