Skip to content

Commit a4afffc

Browse files
sentinelwebsentinelweb
authored andcommitted
#496 - add comments cancel transfer
1 parent d66690d commit a4afffc

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

shared/src/commonMain/kotlin/uk/co/sentinelweb/cuer/app/service/transfers/MemoryTransfersService.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,27 @@ class MemoryTransfersService(
230230
?: run {
231231
queue
232232
.find { it.id == id }
233-
?.let {
233+
?.let { localQueueTransfer ->
234234
// try to cancel remote
235-
it.takeIf { it.target?.node?.ipport() != localRepository.localNode.ipport() }
235+
localQueueTransfer
236+
.takeIf { it.target?.node?.ipport() != localRepository.localNode.ipport() }
236237
?.also { log.d("Cancel remote") }
237-
?.let { cancelTransfersUsecase.execute(it) }
238-
?.copy(status = Paused) // ensure its in paused stated - otherwise repeating
239-
?.also { addReplaceTransfer(it) }
240-
241-
it.takeIf { it.target?.node?.ipport() == localRepository.localNode.ipport() }
238+
?.also {
239+
// cancel remote item
240+
cancelTransfersUsecase.execute(it)
241+
// ensure its in paused stated - otherwise repeating
242+
?.copy(status = Paused)
243+
?.also { addReplaceTransfer(it) }
244+
// just replace the local queued item
245+
// (if cancel remote items fails above (maybe item isn't there))
246+
?: localQueueTransfer
247+
.copy(status = Paused)
248+
.also { addReplaceTransfer(it) }
249+
}
250+
251+
// if item has local target then set to pause - (maybe not in inProgressTransfers)
252+
localQueueTransfer
253+
.takeIf { it.target?.node?.ipport() == localRepository.localNode.ipport() }
242254
?.copy(status = Paused)
243255
?.also { addReplaceTransfer(it) }
244256
}

0 commit comments

Comments
 (0)