Skip to content

Commit

Permalink
Make authors optional if maintainer overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Aug 15, 2024
1 parent 96241db commit d31ff68
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub struct PackageConfig {
pub license_file_skip_lines: usize,
/// The copyright of the project
/// (Debian's `copyright` file contents).
pub copyright: String,
pub copyright: Option<String>,
pub changelog: Option<String>,
/// The homepage URL of the project.
pub homepage: Option<String>,
Expand Down Expand Up @@ -591,6 +591,7 @@ impl PackageConfig {
}
}

let has_maintainer_override = overrides.maintainer.is_some();
Ok(Self {
default_timestamp,
raw_assets: deb.assets.take().map(|assets| Self::parse_assets(assets, listener)).transpose()?,
Expand All @@ -600,12 +601,16 @@ impl PackageConfig {
license,
license_file_rel_path,
license_file_skip_lines,
copyright: deb.copyright.take().ok_or_then(|| {
if cargo_package.authors().is_empty() {
return Err("The package must have a copyright or authors property".into());
}
Ok(cargo_package.authors().join(", "))
})?,
copyright: match deb.copyright.take() {
ok @ Some(_) => ok,
_ if !cargo_package.authors().is_empty() => Some(cargo_package.authors().join(", ")),
_ if has_maintainer_override => {
// generally we'd prefer to have real authors to credit copyright to, but this is now an optional field.
// As a compromise if the maintainer is set on the command-line, assume they can't fix the metadata, and let it be missing.
None
},
_ => return Err("The package must have a copyright or authors property".into()),
},
homepage: cargo_package.homepage().map(From::from),
documentation: cargo_package.documentation().map(From::from),
repository: cargo_package.repository.take().map(|v| v.unwrap()),
Expand Down Expand Up @@ -936,11 +941,13 @@ This will be hard error in a future release of cargo-deb.", source_path.display(
pub(crate) fn append_copyright_metadata(&self, copyright: &mut Vec<u8>) -> Result<(), CargoDebError> {
writeln!(copyright, "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/")?;
writeln!(copyright, "Upstream-Name: {}", self.name)?;
if let Some(source) = self.repository.as_ref().or(self.homepage.as_ref()) {
if let Some(source) = self.repository.as_deref().or(self.homepage.as_deref()) {
writeln!(copyright, "Source: {source}")?;
}
writeln!(copyright, "Copyright: {}", self.copyright)?;
if let Some(ref license) = self.license {
if let Some(c) = self.copyright.as_deref() {
writeln!(copyright, "Copyright: {c}")?;
}
if let Some(license) = self.license.as_deref() {
writeln!(copyright, "License: {license}")?;
}
Ok(())
Expand Down

0 comments on commit d31ff68

Please sign in to comment.