Skip to content

Attempt to retain current location when loading a different platform #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 16, 2020
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euv

export CRATESFYI_PREFIX=/opt/docsrs/prefix
export DOCS_RS_DOCKER=true
export RUST_LOG=cratesfyi,rustwide=info
export RUST_LOG=${RUST_LOG-cratesfyi,rustwide=info}
export PATH="$PATH:/build/target/release"

# Try migrating the database multiple times if it fails
Expand Down
15 changes: 15 additions & 0 deletions src/db/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ pub fn migrate(version: Option<Version>, conn: &Connection) -> CratesfyiResult<(
// downgrade query
"DROP TABLE crate_priorities;",
),
migration!(
context,
// version
12,
// description
"Mark doc_targets non-nullable (it has a default of empty array anyway)",
// upgrade query
"
ALTER TABLE releases ALTER COLUMN doc_targets SET NOT NULL;
",
// downgrade query
"
ALTER TABLE releases ALTER COLUMN doc_targets DROP NOT NULL;
"
),
];

for migration in migrations {
Expand Down
10 changes: 9 additions & 1 deletion src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ impl<'a> FakeRelease<'a> {
}

pub(crate) fn default_target(mut self, target: &'a str) -> Self {
self = self.add_target(target);
self.default_target = Some(target);
self
}

pub(crate) fn add_target(mut self, target: &str) -> Self {
self.doc_targets.push(target.into());
self
}

pub(crate) fn binary(mut self, bin: bool) -> Self {
self.has_docs = !bin;
if bin {
Expand All @@ -112,9 +118,11 @@ impl<'a> FakeRelease<'a> {
}

pub(crate) fn add_platform<S: Into<String>>(mut self, platform: S) -> Self {
let platform = platform.into();
let name = self.package.targets[0].name.clone();
let target = Target::dummy_lib(name, Some(platform.into()));
let target = Target::dummy_lib(name, Some(platform.clone()));
self.package.targets.push(target);
self.doc_targets.push(platform);
self
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ pub(crate) struct TestEnvironment {

impl TestEnvironment {
fn new() -> Self {
// If this fails it's probably already initialized
let _ = env_logger::try_init();
Self {
db: OnceCell::new(),
frontend: OnceCell::new(),
Expand Down
16 changes: 14 additions & 2 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct CrateDetails {
github_issues: Option<i32>,
pub(crate) metadata: MetaData,
is_library: bool,
doc_targets: Option<Json>,
pub(crate) doc_targets: Vec<String>,
license: Option<String>,
documentation_url: Option<String>,
}
Expand Down Expand Up @@ -185,6 +185,18 @@ impl CrateDetails {
default_target: rows.get(0).get(25),
};

let doc_targets = {
let data: Json = rows.get(0).get(22);
data.as_array()
.map(|array| {
array
.iter()
.filter_map(|item| item.as_string().map(|s| s.to_owned()))
.collect()
})
.unwrap_or_else(Vec::new)
};

let mut crate_details = CrateDetails {
name: rows.get(0).get(2),
version: rows.get(0).get(3),
Expand All @@ -211,7 +223,7 @@ impl CrateDetails {
github_issues: rows.get(0).get(20),
metadata,
is_library: rows.get(0).get(21),
doc_targets: rows.get(0).get(22),
doc_targets,
license: rows.get(0).get(23),
documentation_url: rows.get(0).get(24),
};
Expand Down
4 changes: 4 additions & 0 deletions src/web/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ pub(super) fn build_routes() -> Routes {
"/crate/:name/:version/source/*",
super::source::source_browser_handler,
);
routes.internal_page(
"/crate/:name/:version/target-redirect/*",
super::rustdoc::target_redirect_handler,
);

routes.rustdoc_page("/:crate", super::rustdoc::rustdoc_redirector_handler);
routes.rustdoc_page("/:crate/", super::rustdoc::rustdoc_redirector_handler);
Expand Down
Loading