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:
@@ -186,12 +186,7 @@ pub struct Download {
|
||||
impl Download {
|
||||
#[must_use]
|
||||
pub const fn is_finished(&self) -> bool {
|
||||
matches!(
|
||||
self.status,
|
||||
DownloadStatus::Completed
|
||||
| DownloadStatus::Failed(_)
|
||||
| DownloadStatus::TimedOut
|
||||
)
|
||||
self.status.is_terminal()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -234,11 +229,25 @@ pub enum DownloadStatus {
|
||||
total_bytes: u64,
|
||||
},
|
||||
Completed,
|
||||
Cancelled,
|
||||
/// Failed, optionally with a human-readable reason.
|
||||
Failed(Option<String>),
|
||||
TimedOut,
|
||||
}
|
||||
|
||||
impl DownloadStatus {
|
||||
#[must_use]
|
||||
pub const fn is_terminal(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::Completed
|
||||
| Self::Cancelled
|
||||
| Self::Failed(_)
|
||||
| Self::TimedOut
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a user is reachable, as the server reports it.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum UserStatus {
|
||||
|
||||
Reference in New Issue
Block a user