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:
@@ -15,7 +15,7 @@ pub mod transfer;
|
||||
pub mod wish;
|
||||
|
||||
use crate::api::SessionApi;
|
||||
use crate::cli::{Commands, MessageCommand, RoomCommand};
|
||||
use crate::cli::{Commands, MessageCommand, RoomCommand, TransferCommand};
|
||||
use crate::output::{CliError, CliResult, Exit, Out, PortmapRecord};
|
||||
use crate::port_mapping::{self, PortMapper};
|
||||
use crate::remote::{Endpoint, RemoteSession};
|
||||
@@ -286,6 +286,9 @@ fn dispatch(ctx: &Ctx, command: Commands) -> CliResult {
|
||||
match command {
|
||||
Commands::Search(args) => transfer::search(ctx, &args),
|
||||
Commands::Download(args) => transfer::download(ctx, &args),
|
||||
Commands::Transfer(TransferCommand::Cancel { user, path }) => {
|
||||
transfer::cancel(ctx, &user, &path)
|
||||
}
|
||||
Commands::Get(args) => transfer::get(ctx, &args),
|
||||
Commands::Browse(args) => social::browse(ctx, &args),
|
||||
Commands::Room(RoomCommand::List { timeout }) => {
|
||||
|
||||
@@ -553,6 +553,9 @@ fn download_one(
|
||||
reason.unwrap_or_else(|| "the transfer failed".to_string()),
|
||||
));
|
||||
}
|
||||
Ok(DownloadStatus::Cancelled) => {
|
||||
return Err(CliError::transfer("the transfer was cancelled"));
|
||||
}
|
||||
Ok(DownloadStatus::Queued) => {
|
||||
out.status(&format!(
|
||||
"queued behind {}'s uploads",
|
||||
@@ -585,6 +588,19 @@ fn download_one(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cancel(ctx: &Ctx, user: &str, path: &str) -> CliResult {
|
||||
let session = Session::open(ctx)?;
|
||||
if session.client.cancel_download(user, path)
|
||||
| session.client.cancel_upload(user, path)
|
||||
{
|
||||
ctx.out.status(&format!("cancelled {path} ({user})"));
|
||||
return Ok(());
|
||||
}
|
||||
Err(CliError::no_results(format!(
|
||||
"no download or upload of {path} with {user}"
|
||||
)))
|
||||
}
|
||||
|
||||
/// Parse `search`/`browse` output back into download requests.
|
||||
///
|
||||
/// Both shapes this program emits are accepted: a JSON object per line, or
|
||||
|
||||
Reference in New Issue
Block a user