feat: cancel a download from the TUI, the CLI, and the daemon

Closes #54.

A download can now be cancelled whether it is queued, in progress, or
paused. Cancelled is a terminal status: the store refuses to overwrite
it, the status channel relays nothing after it, the partial file is
deleted, and the transfer thread releases its socket at its next
one-second poll instead of the 30s read deadline. A queued download that
is cancelled declines the peer's later offer with TransferResponse
"Cancelled", and an inbound file connection for it is refused. A fresh
download of the same file evicts the dead row so it is not shadowed,
and a cancelled transfer is not re-queued after a restart.

Surfaces: Client::cancel_download, download.cancel over RPC, `transfer
cancel <user> <path>` on the CLI (which also stops an upload by that
name), and x in the transfers pane, where d dismisses the row.
This commit is contained in:
Michel de Graaf
2026-09-06 21:40:45 +02:00
parent 7bc696cab6
commit aa61a1a434
38 changed files with 1139 additions and 102 deletions
+1 -10
View File
@@ -469,16 +469,7 @@ fn save(
let downloads: Vec<PersistedDownload> = session
.get_all_downloads()
.iter()
.map(|download| PersistedDownload {
username: download.username.clone(),
filename: download.filename.clone(),
size: download.size,
download_directory: download.download_directory.clone(),
completed: matches!(
download.status,
soulseek_rs::DownloadStatus::Completed
),
})
.filter_map(PersistedDownload::capture)
.collect();
let _ = store.save_downloads(&downloads);
+5
View File
@@ -44,6 +44,7 @@ fn params_schema(method: Method, generator: &mut SchemaGenerator) -> Value {
| Method::DownloadResume
| Method::DownloadRemove
| Method::DownloadRemoveQueued
| Method::DownloadCancel
| Method::UploadCancel => schema_of::<TransferRef>(generator),
Method::DownloadSetDir => schema_of::<DirectoryParams>(generator),
Method::UploadSlots => schema_of::<SlotsParams>(generator),
@@ -108,6 +109,7 @@ fn result_schema(method: Method, generator: &mut SchemaGenerator) -> Value {
| Method::DownloadResume
| Method::DownloadRemove
| Method::DownloadRemoveQueued
| Method::DownloadCancel
| Method::DownloadSetDir
| Method::UploadCancel
| Method::UploadSlots
@@ -162,6 +164,9 @@ fn summary(method: Method) -> &'static str {
Method::DownloadResume => "Resume a paused transfer.",
Method::DownloadRemove => "Forget a transfer entirely.",
Method::DownloadRemoveQueued => "Drop a transfer that has not started.",
Method::DownloadCancel => {
"Stop a download, queued or in progress; its partial file is deleted."
}
Method::DownloadSetDir => {
"Land future transfers in a different folder on the daemon's host."
}
+3
View File
@@ -111,6 +111,7 @@ pub enum DownloadStatusDto {
total_bytes: u64,
},
Completed,
Cancelled,
Failed {
reason: Option<String>,
},
@@ -138,6 +139,7 @@ impl From<&DownloadStatus> for DownloadStatusDto {
total_bytes: *total_bytes,
},
DownloadStatus::Completed => Self::Completed,
DownloadStatus::Cancelled => Self::Cancelled,
DownloadStatus::Failed(reason) => Self::Failed {
reason: reason.clone(),
},
@@ -167,6 +169,7 @@ impl From<DownloadStatusDto> for DownloadStatus {
total_bytes,
},
DownloadStatusDto::Completed => Self::Completed,
DownloadStatusDto::Cancelled => Self::Cancelled,
DownloadStatusDto::Failed { reason } => Self::Failed(reason),
DownloadStatusDto::TimedOut => Self::TimedOut,
}
+2
View File
@@ -90,6 +90,7 @@ wire_vocabulary! {
DownloadResume => "download.resume",
DownloadRemove => "download.remove",
DownloadRemoveQueued => "download.remove_queued",
DownloadCancel => "download.cancel",
DownloadSetDir => "download.set_dir",
UploadList => "upload.list",
UploadCancel => "upload.cancel",
@@ -194,6 +195,7 @@ mod tests {
total_bytes: 100,
},
DownloadStatus::Completed,
DownloadStatus::Cancelled,
DownloadStatus::Failed(Some("gone".into())),
DownloadStatus::Failed(None),
DownloadStatus::TimedOut,
+12
View File
@@ -184,6 +184,15 @@ impl Daemon {
),
})
}
Method::DownloadCancel => {
let transfer: TransferRef = parse(params)?;
ok(Ack {
ok: self.session.cancel_download(
&transfer.username,
&transfer.filename,
),
})
}
Method::UploadList => ok(Uploads {
uploads: self
@@ -846,6 +855,9 @@ mod tests {
fn cancel_upload(&self, _username: &str, _filename: &str) -> bool {
false
}
fn cancel_download(&self, _username: &str, _filename: &str) -> bool {
false
}
fn set_upload_slots(&self, _slots: usize) {}
fn check_privileges(&self) -> soulseek_rs::Result<()> {
Ok(())