Skip to content

Commit fa1cac4

Browse files
committed
added keep-data option to RemoveTorrent command
1 parent e8a4831 commit fa1cac4

File tree

8 files changed

+24
-11
lines changed

8 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.1.0] - 2025-01-02
9+
10+
### Added
11+
12+
- "keep-data" option to RemoveTorrent command.
13+
814
## [2.0.0] - 2024-12-20
915

1016
### Changed

internal/console/console.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ func (c *Console) removeTorrent(g *gocui.Gui, v *gocui.View) error {
934934
id := c.selectedID
935935
c.m.Unlock()
936936

937-
err := c.client.RemoveTorrent(id)
937+
err := c.client.RemoveTorrent(id, false)
938938
if err != nil {
939939
return err
940940
}

internal/rpctypes/rpctypes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ type AddURIResponse struct {
221221

222222
// RemoveTorrentRequest contains request arguments for Session.RemoveTorrent method.
223223
type RemoveTorrentRequest struct {
224-
ID string
224+
ID string
225+
KeepData bool
225226
}
226227

227228
// RemoveTorrentResponse contains response arguments for Session.RemoveTorrent method.

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ func main() {
209209
Name: "id",
210210
Required: true,
211211
},
212+
cli.BoolFlag{
213+
Name: "keep-data",
214+
},
212215
},
213216
},
214217
{
@@ -959,7 +962,7 @@ func handleAdd(c *cli.Context) error {
959962
}
960963

961964
func handleRemove(c *cli.Context) error {
962-
return clt.RemoveTorrent(c.String("id"))
965+
return clt.RemoveTorrent(c.String("id"), c.Bool("keep-data"))
963966
}
964967

965968
func handleCleanDatabase(c *cli.Context) error {

rainrpc/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func (c *Client) AddURI(uri string, options *AddTorrentOptions) (*rpctypes.Torre
9696
}
9797

9898
// RemoveTorrent removes a torrent from remote Session and deletes its data.
99-
func (c *Client) RemoveTorrent(id string) error {
100-
args := rpctypes.RemoveTorrentRequest{ID: id}
99+
func (c *Client) RemoveTorrent(id string, keepData bool) error {
100+
args := rpctypes.RemoveTorrentRequest{ID: id, KeepData: keepData}
101101
var reply rpctypes.RemoveTorrentResponse
102102
return c.client.Call("Session.RemoveTorrent", args, &reply)
103103
}

torrent/session.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,10 @@ func (s *Session) GetTorrent(id string) *Torrent {
341341
}
342342

343343
// RemoveTorrent removes the torrent from the session and delete its files.
344-
func (s *Session) RemoveTorrent(id string) error {
344+
func (s *Session) RemoveTorrent(id string, keepData bool) error {
345345
t, err := s.removeTorrentFromClient(id)
346346
if t != nil {
347-
err = s.stopAndRemoveData(t)
347+
err = s.stopAndRemoveData(t, keepData)
348348
}
349349
return err
350350
}
@@ -384,9 +384,12 @@ func (s *Session) removeTorrentFromClient(id string) (*Torrent, error) {
384384
})
385385
}
386386

387-
func (s *Session) stopAndRemoveData(t *Torrent) error {
387+
func (s *Session) stopAndRemoveData(t *Torrent, keepData bool) error {
388388
t.torrent.Close()
389389
s.releasePort(t.torrent.port)
390+
if keepData {
391+
return nil
392+
}
390393
var err error
391394
var dest string
392395
if s.config.DataDirIncludesTorrentID {

torrent/session_rpc_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func newTorrent(t *Torrent) rpctypes.Torrent {
8989
}
9090

9191
func (h *rpcHandler) RemoveTorrent(args *rpctypes.RemoveTorrentRequest, reply *rpctypes.RemoveTorrentResponse) error {
92-
return h.session.RemoveTorrent(args.ID)
92+
return h.session.RemoveTorrent(args.ID, args.KeepData)
9393
}
9494

9595
func (h *rpcHandler) GetMagnet(args *rpctypes.GetMagnetRequest, reply *rpctypes.GetMagnetResponse) error {
@@ -523,7 +523,7 @@ func (h *rpcHandler) handleMoveTorrent(w http.ResponseWriter, r *http.Request) {
523523
http.Error(w, err.Error(), http.StatusInternalServerError)
524524
return
525525
}
526-
err = h.session.stopAndRemoveData(t)
526+
err = h.session.stopAndRemoveData(t, false)
527527
if err != nil {
528528
h.session.log.Error(err)
529529
http.Error(w, err.Error(), http.StatusInternalServerError)

torrent/session_torrent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (t *Torrent) Move(target string) error {
240240
return fmt.Errorf("http error: %d", resp.StatusCode)
241241
}
242242
defer resp.Body.Close()
243-
return t.torrent.session.RemoveTorrent(t.torrent.id)
243+
return t.torrent.session.RemoveTorrent(t.torrent.id, true)
244244
}
245245

246246
func (t *Torrent) prepareBody(pw *io.PipeWriter, mw *multipart.Writer, spec *boltdbresumer.Spec) {

0 commit comments

Comments
 (0)