Files
Netcatty/application/state/sftp/transferCancelLatch.ts
T
bincxz d165e158f7 fix(sftp): unify transfer control under process-level TransferRuntime
Pause and resume now go through one process-level control plane that survives
panel/terminal close: TransferRuntime + soft latches/epochs/walk registry,
soft-then-hard resume, dual-epoch-safe progress, and no-owner soft control.
2026-07-26 21:27:01 +08:00

40 lines
1.2 KiB
TypeScript

/**
* Process-wide cancel flags for SFTP transfers.
*
* Directory walks and stream arms check these so Cancel from the global
* transfer center still stops work after the React owner unmounts.
*/
const cancelledIds = new Set<string>();
export function markTransferCancelled(taskId: string): void {
cancelledIds.add(taskId);
}
export function markTransferCancelledTree(rootTaskId: string, childIds: readonly string[] = []): void {
cancelledIds.add(rootTaskId);
for (const id of childIds) cancelledIds.add(id);
}
export function clearTransferCancelled(taskId: string): void {
cancelledIds.delete(taskId);
}
export function clearTransferCancelledTree(rootTaskId: string, childIds: readonly string[] = []): void {
cancelledIds.delete(rootTaskId);
for (const id of childIds) cancelledIds.delete(id);
}
export function isTransferCancelledFlag(taskId: string): boolean {
return cancelledIds.has(taskId);
}
export function isTransferOrRootCancelled(rootTaskId: string, taskId?: string): boolean {
return cancelledIds.has(rootTaskId) || (!!taskId && cancelledIds.has(taskId));
}
/** Test helper. */
export function resetTransferCancelLatchesForTests(): void {
cancelledIds.clear();
}