diff --git a/src/main.rs b/src/main.rs index cfdabce..908f1b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -367,7 +367,7 @@ fn main() { .about("Upload the built source package to a PPA") .arg(arg!(--ppa "Upload to a PPA (format: user/ppa_name)")) .arg(arg!([changes] "Explicit .changes file to upload (default: the one built from this package, next to the source tree)").required(false)) - .arg(arg!(--force "Upload even if this exact .changes file was already uploaded to the target")), + .arg(arg!(--force "Upload even if this exact .changes file was already uploaded to the target, skipping the pre-upload mistake checks")), ) .subcommand( Command::new("deb") diff --git a/src/put/changes.rs b/src/put/changes.rs index 0ad6df5..d58a3be 100644 --- a/src/put/changes.rs +++ b/src/put/changes.rs @@ -57,6 +57,13 @@ pub struct ChangesFile { pub version: String, /// `Distribution` field. pub distribution: String, + /// `Changed-By` field (the changelog maintainer), when present. + pub changed_by: Option, + /// `Maintainer` field (the source stanza maintainer), when present. + pub maintainer: Option, + /// `Launchpad-Bugs-Fixed` field (Launchpad bugs referenced in the + /// changelog), when present. + pub launchpad_bugs_fixed: Option, /// Files to upload, in listing order. The `.changes` file itself is not /// part of this list: it is uploaded last, like dput does. pub files: Vec, @@ -146,6 +153,9 @@ fn parse_body(content: &str, path: &Path) -> Result\nChecksums-Sha256:{}\n", + Maintainer: A B \nChanged-By: C D \nChecksums-Sha256:{}\n", // deb822 continuation lines are indented cs.field_sha256().replace('\n', "\n ") ); @@ -282,6 +292,9 @@ iQIzBAABCgAdFiEEfakefingerprintXfakecommentlength assert_eq!(changes.source, "hello"); assert_eq!(changes.version, "1.0-1"); assert_eq!(changes.distribution, "resolute"); + assert_eq!(changes.changed_by.as_deref(), Some("C D ")); + assert_eq!(changes.maintainer.as_deref(), Some("A B ")); + assert_eq!(changes.launchpad_bugs_fixed, None); assert_eq!(changes.files.len(), 2); assert_eq!(changes.files[0].name, "hello_1.0-1.dsc"); diff --git a/src/put/checks.rs b/src/put/checks.rs new file mode 100644 index 0000000..874c05e --- /dev/null +++ b/src/put/checks.rs @@ -0,0 +1,633 @@ +//! Pre-upload mistake guards: refuse or question uploads carrying common +//! mistakes the archive queue would accept silently, before anything +//! leaves the machine. Adapted from Christian Ehrhardt's dput hooks +//! (`ubuntu-helpers/cpaelzer/.dput.d/hooks`), which guard the same +//! mistakes for plain `dput` uploads. +//! +//! Each guard is a pure [`Verdict`], so every decision is testable +//! without a terminal; [`run`] applies them in order, asking the prompter +//! for the questionable ones. `--force` skips the whole module (the +//! caller decides): it is the explicit "upload anyway" answer. + +use std::path::Path; + +use crate::debian::version::DebianVersion; +use crate::report::Prompter; + +use super::changes::ChangesFile; + +/// What one guard decided about the upload. +#[derive(Debug, PartialEq, Eq)] +enum Verdict { + /// No mistake detected. + Proceed, + /// The upload may proceed only if the user confirms; the prompter's + /// default answer is "no", so headless runs refuse. + Ask { + /// What looks wrong, logged before the question and reused as the + /// refusal reason. + reason: String, + /// The yes/no question. + question: String, + }, + /// Refuse outright: the mistake is unambiguous. + Refuse(String), +} + +/// Run every guard. `tree` is the source directory the tree-level checks +/// validate, `None` when the upload does not carry one next to it +/// (an explicit `--changes` collected away from the tree). +pub(super) async fn run( + changes: &ChangesFile, + tree: Option<&Path>, + prompter: &dyn Prompter, +) -> Result<(), Box> { + let target = target_series_release(&changes.distribution).await; + for verdict in [ + bad_author(changes), + no_bug(changes), + placeholder_bug(changes), + release_mismatch(changes, target.as_ref()), + update_maintainer(changes), + patches_in_native(changes, tree), + ] { + apply(verdict, prompter)?; + } + Ok(()) +} + +/// Apply one guard's verdict: questions go to the prompter (whose default +/// answer refuses), refusals become upload errors. Both end in the same +/// `--force` hint, the single way past the guards. +fn apply(verdict: Verdict, prompter: &dyn Prompter) -> Result<(), Box> { + match verdict { + Verdict::Proceed => Ok(()), + Verdict::Refuse(reason) => Err(refusal(reason)), + Verdict::Ask { reason, question } => { + log::warn!("{reason}"); + if prompter.confirm(&question, false)? { + Ok(()) + } else { + Err(refusal(reason)) + } + } + } +} + +/// The error for a guard that said no: the reason plus the way out. +fn refusal(reason: String) -> Box { + format!("{reason} (pass --force to upload anyway)").into() +} + +/// Stop uploads whose `Changed-By` is a `ubuntu@` or `root@` address: +/// built in a container or VM, the changelog picked up the machine's +/// default identity, and sponsoring or publishing would push that address +/// into the archive. +fn bad_author(changes: &ChangesFile) -> Verdict { + let Some(author) = &changes.changed_by else { + return Verdict::Proceed; + }; + if author.contains("ubuntu@") || author.contains("root@") { + Verdict::Refuse(format!( + "Changed-By '{author}' carries an ubuntu@ or root@ address, \ + usually a container or VM default identity leaked into the \ + changelog: set your real identity (DEBEMAIL/DEBFULLNAME or \ + 'git config user.email'), fix debian/changelog and rebuild \ + with `pkh build`" + )) + } else { + Verdict::Proceed + } +} + +/// Question uploads that reference no Launchpad bug: an upload almost +/// always fixes a bug, and the missing reference only shows up in the +/// changelog later review. +fn no_bug(changes: &ChangesFile) -> Verdict { + let has_bugs = changes + .launchpad_bugs_fixed + .as_deref() + .is_some_and(|bugs| !bugs.trim().is_empty()); + if has_bugs { + return Verdict::Proceed; + } + Verdict::Ask { + reason: "the upload references no Launchpad bug: add 'LP: #NNN' to \ + the changelog entry for the bug it fixes" + .to_string(), + question: "Upload without Launchpad bug references?".to_string(), + } +} + +/// Question uploads whose bug numbers are common placeholders (`1234`, +/// `9999`): the entry was written before the real bug number was known +/// and the placeholder would end up in the archive. +fn placeholder_bug(changes: &ChangesFile) -> Verdict { + let Some(bugs) = &changes.launchpad_bugs_fixed else { + return Verdict::Proceed; + }; + let placeholders = ["1234", "9999"]; + let flagged: Vec = bug_numbers(bugs) + .into_iter() + .filter(|bug| placeholders.iter().any(|p| bug.starts_with(p))) + .collect(); + if flagged.is_empty() { + return Verdict::Proceed; + } + Verdict::Ask { + reason: format!( + "Launchpad bug reference(s) {} look like placeholder numbers", + flagged.join(", ") + ), + question: "Upload with placeholder bug references?".to_string(), + } +} + +/// The bug numbers of a `Launchpad-Bugs-Fixed` value, as strings so the +/// placeholder prefixes keep working whatever separator the field carries +/// (dpkg renders spaces, the changelog convention uses commas). +fn bug_numbers(bugs: &str) -> Vec { + bugs.split(|c: char| !c.is_ascii_digit()) + .filter(|token| !token.is_empty()) + .map(str::to_string) + .collect() +} + +/// Question uploads whose backport suffix does not match the target +/// series: a version like `1.0-0ubuntu1~20.10` uploaded to `focal` +/// (release `20.04`) carries the wrong series' number. +/// +/// `target` is the target series' `(codename, release number)`, `None` +/// when it is not a versioned Ubuntu series (the check then skips). +fn release_mismatch(changes: &ChangesFile, target: Option<&(String, String)>) -> Verdict { + let Some((codename, number)) = target else { + return Verdict::Proceed; + }; + let Some(ubuntu_idx) = changes.version.find("ubuntu") else { + return Verdict::Proceed; + }; + // Only the part after `ubuntu` is scanned: upstream versions carry + // their own numbers, and a date there (`24.09.1`) is not a series + // marker. dpkg scans the same span (everything following `ubuntu`). + let ubuntu_part = &changes.version[ubuntu_idx + "ubuntu".len()..]; + let mismatched: Vec<&str> = release_numbers(ubuntu_part) + .into_iter() + .filter(|found| found != number) + .collect(); + if mismatched.is_empty() { + return Verdict::Proceed; + } + Verdict::Ask { + reason: format!( + "the version {} carries {} but the target series {} is {}: a \ + backport suffix does not match the series it uploads to", + changes.version, + mismatched.join(", "), + codename, + number + ), + question: "Upload with a backport suffix not matching the target series?".to_string(), + } +} + +/// Every `\d\d.\d\d` release-looking number in `text`, unique and in +/// order. A byte scan instead of a regex: the pattern can overlap itself +/// (`23.45.67` holds two), which the regex crate cannot express. +fn release_numbers(text: &str) -> Vec<&str> { + let bytes = text.as_bytes(); + let mut found = Vec::new(); + for (i, window) in bytes.windows(5).enumerate() { + let is_release = window[0].is_ascii_digit() + && window[1].is_ascii_digit() + && window[2] == b'.' + && window[3].is_ascii_digit() + && window[4].is_ascii_digit(); + // A match starts on an ASCII digit, so the byte offset is a char + // boundary and the slice is always valid. + if is_release && !found.contains(&&text[i..i + 5]) { + found.push(&text[i..i + 5]); + } + } + found +} + +/// The `(codename, release number)` of the changes' target series, when it +/// is a versioned Ubuntu series; `None` otherwise (pocket suffixes like +/// `focal-proposed` resolve through the codename, non-Ubuntu series and +/// lookup failures skip the release check). +async fn target_series_release(distribution: &str) -> Option<(String, String)> { + let codename = distribution.split('-').next().unwrap_or(distribution); + match crate::distro_info::get_series_release_number(codename).await { + Ok(Some((dist, number))) if dist == "ubuntu" => Some((codename.to_string(), number)), + _ => None, + } +} + +/// Question Ubuntu-marked versions (`1.0-1ubuntuN`) whose `Maintainer` is +/// not an ubuntu.com address: carrying Ubuntu changes without running +/// `update-maintainer` leaves them owned by the original (usually Debian) +/// maintainer. +fn update_maintainer(changes: &ChangesFile) -> Verdict { + if !ubuntu_marked_version(&changes.version) { + return Verdict::Proceed; + } + let Some(maintainer) = &changes.maintainer else { + return Verdict::Proceed; + }; + if has_ubuntu_maintainer(maintainer) { + return Verdict::Proceed; + } + Verdict::Ask { + reason: format!( + "the version {} carries Ubuntu changes but the Maintainer \ + '{maintainer}' is not an ubuntu.com address: run \ + 'update-maintainer' (ubuntu-dev-tools) and rebuild, so Ubuntu \ + modifications are owned by an Ubuntu maintainer", + changes.version + ), + question: "Upload without an ubuntu.com maintainer?".to_string(), + } +} + +/// Whether the version carries Ubuntu's own revision marker: an `ubuntu` +/// word right after a digit, with only digits and dots between it and the +/// end of the version (`1.0-1ubuntu1`, `1.0-1ubuntu2.3`). Anchoring at the +/// end keeps upstream components that merely contain `ubuntu` +/// (`1.0+gitubuntu-main`) out; the point-update digits extend dpkg's +/// `\dubuntu\d*$` reading, which misses `1ubuntu2.3` SRU versions. +fn ubuntu_marked_version(version: &str) -> bool { + version.match_indices("ubuntu").any(|(idx, _)| { + let before = version[..idx] + .chars() + .last() + .is_some_and(|c| c.is_ascii_digit()); + let after = &version[idx + "ubuntu".len()..]; + before && after.chars().all(|c| c.is_ascii_digit() || c == '.') + }) +} + +/// Whether the maintainer address is an ubuntu.com one: the address +/// `update-maintainer` sets (`ubuntu-devel-discuss@lists.ubuntu.com`) or +/// an Ubuntu developer's. The boundary check (an `@` or `.` before +/// `ubuntu.com`) keeps look-alike domains like `notubuntu.com` in. +fn has_ubuntu_maintainer(maintainer: &str) -> bool { + let Some(lt) = maintainer.rfind('<') else { + return false; + }; + let email = maintainer[lt + 1..].trim_end_matches('>'); + email.ends_with("@ubuntu.com") || email.ends_with(".ubuntu.com") +} + +/// Refuse native packages carrying `debian/patches/series`: quilt patches +/// are never applied in a native package, so the fixes they carry would +/// silently miss the build. +fn patches_in_native(changes: &ChangesFile, tree: Option<&Path>) -> Verdict { + let Some(tree) = tree else { + return Verdict::Proceed; + }; + if !is_native(tree, &changes.version) || !tree.join("debian/patches/series").is_file() { + return Verdict::Proceed; + } + Verdict::Refuse( + "the package is native but debian/patches/series exists: quilt \ + patches are never applied in a native package, so the fixes they \ + carry would silently miss the build. Fold the patches into the \ + source or switch debian/source/format to '3.0 (quilt)'" + .to_string(), + ) +} + +/// Whether the package in `tree` is native: `debian/source/format` says so +/// when present, otherwise the version decides (an upload without a +/// Debian revision is native by construction). +fn is_native(tree: &Path, version: &str) -> bool { + match std::fs::read_to_string(tree.join("debian/source/format")) { + Ok(format) => format.trim().ends_with("(native)"), + Err(_) => { + DebianVersion::parse(version).is_ok_and(|parsed| parsed.debian_revision.is_none()) + } + } +} + +#[cfg(test)] +mod tests { + use std::path::PathBuf; + + use super::*; + + /// A changes file with these fields, everything else minimal. + fn changes(version: &str, changed_by: Option<&str>, maintainer: Option<&str>) -> ChangesFile { + changes_with_bugs(version, changed_by, maintainer, None) + } + + /// A changes file that also carries a `Launchpad-Bugs-Fixed` value. + fn changes_with_bugs( + version: &str, + changed_by: Option<&str>, + maintainer: Option<&str>, + bugs: Option<&str>, + ) -> ChangesFile { + ChangesFile { + path: PathBuf::from("hello_1.0-1_source.changes"), + source: "hello".to_string(), + version: version.to_string(), + distribution: "resolute".to_string(), + changed_by: changed_by.map(str::to_string), + maintainer: maintainer.map(str::to_string), + launchpad_bugs_fixed: bugs.map(str::to_string), + files: Vec::new(), + } + } + + #[test] + fn bad_author_stops_machine_identities() { + assert_eq!( + bad_author(&changes("1.0-1", Some("root "), None)), + Verdict::Refuse( + "Changed-By 'root ' carries an ubuntu@ or \ + root@ address, usually a container or VM default identity \ + leaked into the changelog: set your real identity \ + (DEBEMAIL/DEBFULLNAME or 'git config user.email'), fix \ + debian/changelog and rebuild with `pkh build`" + .to_string() + ) + ); + assert!(matches!( + bad_author(&changes("1.0-1", Some("Ubuntu "), None)), + Verdict::Refuse(_) + )); + assert_eq!( + bad_author(&changes("1.0-1", Some("A B "), None)), + Verdict::Proceed + ); + // No Changed-By field: nothing to judge + assert_eq!(bad_author(&changes("1.0-1", None, None)), Verdict::Proceed); + } + + #[test] + fn no_bug_questions_missing_references() { + assert!(matches!( + no_bug(&changes("1.0-1", Some("A "), None)), + Verdict::Ask { .. } + )); + // An empty field is as good as absent + assert!(matches!( + no_bug(&changes_with_bugs("1.0-1", None, None, Some(" "))), + Verdict::Ask { .. } + )); + assert_eq!( + no_bug(&changes_with_bugs("1.0-1", None, None, Some("123456"))), + Verdict::Proceed + ); + } + + #[test] + fn placeholder_bug_flags_placeholder_prefixes() { + assert!(matches!( + placeholder_bug(&changes_with_bugs("1.0-1", None, None, Some("123456"))), + Verdict::Ask { .. } + )); + assert!(matches!( + placeholder_bug(&changes_with_bugs("1.0-1", None, None, Some("9999"))), + Verdict::Ask { .. } + )); + // Both placeholders in one comma-separated field: both reported + match placeholder_bug(&changes_with_bugs( + "1.0-1", + None, + None, + Some("1234, 99990, 4567"), + )) { + Verdict::Ask { reason, .. } => { + assert!(reason.contains("1234, 99990"), "unexpected: {reason}"); + assert!(!reason.contains("4567"), "unexpected: {reason}"); + } + other => panic!("unexpected verdict: {other:?}"), + } + assert_eq!( + placeholder_bug(&changes_with_bugs("1.0-1", None, None, Some("456789"))), + Verdict::Proceed + ); + assert_eq!( + placeholder_bug(&changes("1.0-1", None, None)), + Verdict::Proceed + ); + } + + #[test] + fn release_mismatch_checks_backport_suffixes() { + let target = ("focal".to_string(), "20.04".to_string()); + + // Matching suffix + assert_eq!( + release_mismatch(&changes("1.0-0ubuntu1~20.04", None, None), Some(&target)), + Verdict::Proceed + ); + // Suffix for another series + assert!(matches!( + release_mismatch(&changes("1.0-0ubuntu1~20.10", None, None), Some(&target)), + Verdict::Ask { .. } + )); + // No ubuntu marker, no suffix: nothing to compare + assert_eq!( + release_mismatch(&changes("1.0-1", None, None), Some(&target)), + Verdict::Proceed + ); + // Numbers in the upstream part do not decide (the scan starts + // after `ubuntu`) + assert_eq!( + release_mismatch(&changes("24.09.1-1ubuntu1", None, None), Some(&target)), + Verdict::Proceed + ); + // Unversioned target (not a versioned Ubuntu series): skipped + assert_eq!( + release_mismatch(&changes("1.0-0ubuntu1~20.10", None, None), None), + Verdict::Proceed + ); + } + + #[test] + fn release_numbers_scans_overlapping_patterns() { + assert_eq!(release_numbers("1~20.04"), vec!["20.04"]); + // `23.45.67` holds two overlapping matches + assert_eq!(release_numbers("23.45.67"), vec!["23.45", "45.67"]); + // Duplicates collapse + assert_eq!(release_numbers("20.04-20.04"), vec!["20.04"]); + assert!(release_numbers("1.2-1").is_empty()); + } + + #[test] + fn update_maintainer_questions_non_ubuntu_maintainers() { + // Ubuntu-marked version, Debian maintainer + assert!(matches!( + update_maintainer(&changes("1.0-1ubuntu1", None, Some("D M "))), + Verdict::Ask { .. } + )); + // Point-update SRU version (`1ubuntu2.3`), the shape dpkg's own + // `\dubuntu\d*$` misses + assert!(matches!( + update_maintainer(&changes( + "1.0-1ubuntu2.22", + None, + Some("D M ") + )), + Verdict::Ask { .. } + )); + // The address update-maintainer sets + assert_eq!( + update_maintainer(&changes( + "1.0-1ubuntu1", + None, + Some("Ubuntu Developers ") + )), + Verdict::Proceed + ); + // An Ubuntu developer's address + assert_eq!( + update_maintainer(&changes("1.0-1ubuntu1", None, Some("U D "))), + Verdict::Proceed + ); + // Look-alike domain: not an ubuntu.com address + assert!(matches!( + update_maintainer(&changes( + "1.0-1ubuntu1", + None, + Some("N U ") + )), + Verdict::Ask { .. } + )); + // Plain revision upload: the check does not apply + assert_eq!( + update_maintainer(&changes("1.0-1", None, Some("D M "))), + Verdict::Proceed + ); + // Upstream component merely containing `ubuntu`: not Ubuntu-marked + assert_eq!( + update_maintainer(&changes( + "1.0+gitubuntu-main-1", + None, + Some("D M ") + )), + Verdict::Proceed + ); + // A `~ppa` tail keeps the marker out of the anchored position + assert_eq!( + update_maintainer(&changes( + "1.0-1ubuntu2~ppa1", + None, + Some("D M ") + )), + Verdict::Proceed + ); + // No Maintainer field: nothing to judge + assert_eq!( + update_maintainer(&changes("1.0-1ubuntu1", None, None)), + Verdict::Proceed + ); + } + + #[test] + fn patches_in_native_refuses_quilt_series() { + let dir = tempfile::tempdir().unwrap(); + + // Native format + series: refused + let native = dir.path().join("native"); + std::fs::create_dir_all(native.join("debian/patches")).unwrap(); + std::fs::create_dir_all(native.join("debian/source")).unwrap(); + std::fs::write(native.join("debian/source/format"), "3.0 (native)\n").unwrap(); + std::fs::write(native.join("debian/patches/series"), "").unwrap(); + assert!(matches!( + patches_in_native(&changes("1.0-1", None, None), Some(&native)), + Verdict::Refuse(_) + )); + + // Quilt format + series: fine + let quilt = dir.path().join("quilt"); + std::fs::create_dir_all(quilt.join("debian/patches")).unwrap(); + std::fs::create_dir_all(quilt.join("debian/source")).unwrap(); + std::fs::write(quilt.join("debian/source/format"), "3.0 (quilt)\n").unwrap(); + std::fs::write(quilt.join("debian/patches/series"), "").unwrap(); + assert_eq!( + patches_in_native(&changes("1.0-1", None, None), Some(&quilt)), + Verdict::Proceed + ); + + // Native format, no series file: fine + let native_clean = dir.path().join("native-clean"); + std::fs::create_dir_all(native_clean.join("debian/source")).unwrap(); + std::fs::write(native_clean.join("debian/source/format"), "3.0 (native)\n").unwrap(); + assert_eq!( + patches_in_native(&changes("1.0-1", None, None), Some(&native_clean)), + Verdict::Proceed + ); + + // No format file: the version decides (no revision = native) + let unversioned = dir.path().join("unversioned"); + std::fs::create_dir_all(unversioned.join("debian/patches")).unwrap(); + std::fs::write(unversioned.join("debian/patches/series"), "").unwrap(); + assert!(matches!( + patches_in_native(&changes("1.0", None, None), Some(&unversioned)), + Verdict::Refuse(_) + )); + assert_eq!( + patches_in_native(&changes("1.0-1", None, None), Some(&unversioned)), + Verdict::Proceed + ); + + // No tree next to the upload: skipped + assert_eq!( + patches_in_native(&changes("1.0", None, None), None), + Verdict::Proceed + ); + } + + /// A prompter answering yes to every question, recording what it was + /// asked. + struct ConfirmYes; + + impl Prompter for ConfirmYes { + fn confirm( + &self, + question: &str, + _default: bool, + ) -> Result> { + assert!(question.ends_with('?'), "unexpected question: {question}"); + Ok(true) + } + } + + #[tokio::test] + async fn run_asks_then_proceeds_on_confirmation() { + // No bugs, placeholder-free upload: the only Ask is no_bug + let changes = changes("1.0-1", Some("A B "), Some("A B ")); + assert!( + run(&changes, None, &ConfirmYes).await.is_ok(), + "a yes answer lets the upload through" + ); + } + + #[tokio::test] + async fn run_refuses_without_confirmation() { + let changes = changes("1.0-1", Some("A B "), Some("A B ")); + let error = run(&changes, None, &crate::report::Quiet) + .await + .unwrap_err() + .to_string(); + assert!( + error.contains("references no Launchpad bug"), + "unexpected: {error}" + ); + assert!(error.contains("--force"), "unexpected: {error}"); + } + + #[tokio::test] + async fn run_stops_machine_identities_before_asking() { + // A bad author is refused outright, with no question in between + let changes = changes("1.0-1", Some("root "), None); + let error = run(&changes, None, &ConfirmYes) + .await + .unwrap_err() + .to_string(); + assert!(error.contains("root@"), "unexpected: {error}"); + } +} diff --git a/src/put/mod.rs b/src/put/mod.rs index 473a67d..79eb945 100644 --- a/src/put/mod.rs +++ b/src/put/mod.rs @@ -6,6 +6,7 @@ //! transport dput's plain `ppa:` profiles use — through [`ftp`]. pub mod changes; +pub mod checks; // The plain-FTP fallback transport: feature-gated (the `ftp` feature) so // the Debian build can drop its one unpackaged dependency; with the // feature off, the SFTP failure path reports the transport as @@ -36,8 +37,8 @@ pub struct PutOptions<'a> { /// current package (from `debian/changelog`) is discovered next to the /// source tree. pub changes: Option, - /// Upload even if this exact `.changes` file was already uploaded to the - /// target. + /// Upload even if this exact `.changes` file was already uploaded to + /// the target, skipping the mistake pre-flight checks. pub force: bool, /// Source package directory (the one containing `debian/`). pub cwd: PathBuf, @@ -105,10 +106,25 @@ async fn put_impl(opts: &PutOptions<'_>) -> Result<(), Box Some(dir.as_path()), + SectionCheckTarget::Skip => None, + }; + checks::run(&changes, tree_dir, opts.prompter).await?; + } + // Pre-flight checks for everything the upload queue only rejects after // processing: a valid Section, a known target series, and the target // PPA actually existing (the SFTP queue itself is a blind write) - match section_check_target(opts.changes.as_deref(), &opts.cwd) { + match tree { SectionCheckTarget::Dir(dir) => check_control_section(&dir, "ubuntu")?, SectionCheckTarget::Skip => log::warn!( "cannot check the Section: '{}' has no debian/control next to \ @@ -945,6 +961,9 @@ mod tests { source: "hello".to_string(), version: version.to_string(), distribution: "resolute".to_string(), + changed_by: None, + maintainer: None, + launchpad_bugs_fixed: None, files: Vec::new(), } }