put: remove partial uploads when the transfer fails

A failed or interrupted upload left the already-uploaded payloads — or
a truncated .changes — in the PPA's incoming area. On failure the
already-uploaded files are now removed best-effort in reverse upload
order with the failed file first, so a .changes never outlives the
payloads it references; the original upload error keeps precedence over
cleanup failures, and record-after-success semantics are unchanged (a
failed upload must not count as uploaded).
This commit is contained in:
2026-09-18 10:36:01 +02:00
parent 231c478d0b
commit e640b153bd
2 changed files with 143 additions and 7 deletions
+12
View File
@@ -632,6 +632,18 @@ pub fn upload_file(
Ok(())
}
/// Remove the remote file `remote` on `host` (SFTP remove). Used by the
/// best-effort cleanup of an interrupted upload: the queue is write-only,
/// so the only remote operation ever needed besides `create` is this one.
pub fn remove_file(
sftp: &ssh2::Sftp,
remote: &str,
host: &str,
) -> Result<(), Box<dyn std::error::Error>> {
sftp.unlink(Path::new(remote))
.map_err(|e| format!("cannot remove remote file {remote} on {host}: {e}").into())
}
/// Open the SFTP subsystem on `session`
pub fn sftp(session: &Session) -> Result<ssh2::Sftp, Box<dyn std::error::Error>> {
session