Skip to content
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

Fix failure with missing readme. #8353

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,13 @@ fn transmit(
ref badges,
ref links,
} = *manifest.metadata();
let readme_content = match *readme {
Some(ref readme) => Some(paths::read(&pkg.root().join(readme))?),
None => None,
};
let readme_content = readme
.as_ref()
.map(|readme| {
paths::read(&pkg.root().join(readme))
.chain_err(|| format!("failed to read `readme` file for package `{}`", pkg))
})
.transpose()?;
if let Some(ref file) = *license_file {
if !pkg.root().join(file).exists() {
bail!("the license file `{}` does not exist", file)
Expand Down
9 changes: 1 addition & 8 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,18 +1209,11 @@ impl TomlManifest {
project.namespaced_features.unwrap_or(false),
)?;

let readme = readme_for_project(package_root, project);
if let Some(ref r) = readme {
if !package_root.join(r).is_file() {
bail!("readme file with name '{}' was not found", r);
}
};

let metadata = ManifestMetadata {
description: project.description.clone(),
homepage: project.homepage.clone(),
documentation: project.documentation.clone(),
readme,
readme: readme_for_project(package_root, project),
authors: project.authors.clone().unwrap_or_default(),
license: project.license.clone(),
license_file: project.license_file.clone(),
Expand Down
42 changes: 41 additions & 1 deletion tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use cargo_test_support::git::{self, repo};
use cargo_test_support::paths;
use cargo_test_support::registry::{self, registry_path, registry_url, Package};
use cargo_test_support::{basic_manifest, project, publish};
use cargo_test_support::{basic_manifest, no_such_file_err_msg, project, publish};
use std::fs;

const CLEAN_FOO_JSON: &str = r#"
Expand Down Expand Up @@ -1341,3 +1341,43 @@ See [..]
)
.run();
}

#[cargo_test]
fn publish_with_missing_readme() {
registry::init();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
license = "MIT"
description = "foo"
homepage = "https://example.com/"
readme = "foo.md"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("publish --no-verify --token sekrit")
.with_status(101)
.with_stderr(&format!(
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[UPLOADING] foo v0.1.0 [..]
[ERROR] failed to read `readme` file for package `foo v0.1.0 ([ROOT]/foo)`

Caused by:
failed to read `[ROOT]/foo/foo.md`

Caused by:
{}
",
no_such_file_err_msg()
))
.run();
}
15 changes: 1 addition & 14 deletions tests/testsuite/read_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,6 @@ fn cargo_read_manifest_defaults_readme_if_true() {
.build();

p.cargo("read-manifest")
.with_json(&manifest_output(&format!(r#""{}""#, "README.md")))
.with_json(&manifest_output(r#""README.md""#))
.run();
}

// If a file named README.md does not exist, and `readme = true`, it should panic.
#[cargo_test]
#[should_panic]
fn cargo_read_manifest_panics_if_default_readme_not_found() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest_with_readme("foo", "true"))
.file("README.txt", "Sample project")
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();

p.cargo("read-manifest").run();
}