feat: allow removing a task with deletion of downloaded data#139
Merged
Conversation
Adds an opt-in deleteFiles flag to DownloadTask.remove(). When true,
the engine dispatches to a new DownloadSource.cleanup() hook so each
protocol can tear down its own data (HTTP/FTP delete via FileAccessor;
torrent calls TorrentEngine.removeTorrent(deleteFiles = true)).
The flag flows through the remote SDK and the daemon server via a
new ?deleteFiles=true query param on DELETE /api/tasks/{id}. The UI's
trash icon now opens a confirmation dialog with a checkbox (resets to
unchecked each open) instead of removing the task silently.
Cleanup is best-effort: failures are logged and never prevent the
task record from being removed.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 261a332a83
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Contributor
DownloadCoordinator.cancel() previously called job.cancel() but did not await the job's finally chain. With remove(deleteFiles = true), the follow-up cleanup ran while the download's FileAccessor was still being closed, causing deletion to race the writer (and fail outright on lock-enforcing platforms like Windows). Capture the job inside the mutex, then join() outside the mutex so callers see a fully-quiesced download by the time cancel() returns. Adds a regression test that pins the ordering by suspending in source.download() until cancellation, then asserting the download's finally has run before cancel() returns. Addresses review feedback on #139.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in
deleteFilesflag toDownloadTask.remove(). Whentrue,the engine dispatches to a new
DownloadSource.cleanup()hook so eachprotocol cleans up its own data:
FileAccessorTorrentEngine.removeTorrent(infoHash, deleteFiles = true)The flag flows through the remote SDK (
RemoteDownloadTask) and the daemonserver via a new
?deleteFiles=truequery param onDELETE /api/tasks/{id}.The UI's trash icon now opens a confirmation dialog with an "Also delete
downloaded file" checkbox (resets to unchecked each open) instead of
removing silently. Cleanup is best-effort — failures are logged and never
prevent the task record from being removed.
docs/api.mdnow documents the fullDownloadTaskinterface including thenew
remove(deleteFiles: Boolean = false)signature. Default isfalse,so existing callers keep current behavior.
Test Plan
task.remove()(no arg) removes only the record, file untouchedtask.remove(deleteFiles = true)on an in-progress HTTP download deletes the partial filetask.remove(deleteFiles = true)on a completed HTTP download deletes the filetask.remove(deleteFiles = true)on a torrent invokesremoveTorrent(..., deleteFiles = true)DELETE /api/tasks/{id}?deleteFiles=trueremoves both record and fileDELETE /api/tasks/{id}(no query param) keeps backward-compatible record-only behaviorDELETE /api/tasks/{id}?deleteFiles=bananafalls back tofalseUnit tests cover all of the above except the UI dialog visual behavior
(no UI test infra in this repo today).