-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdeldata.go
39 lines (33 loc) · 838 Bytes
/
deldata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"strconv"
)
// deldata takes an id or more, and delete the corresponding torrent/s with their data
func deldata(tokens []string) {
// make sure that we got an argument
if len(tokens) == 0 {
send("deldata: needs an ID", false)
return
}
torrents, err := rtorrent.Torrents()
if err != nil {
logger.Print("deldata:", err)
send("deldata: "+err.Error(), false)
return
}
// loop over tokens to read each potential id
for _, i := range tokens {
id, err := strconv.Atoi(i)
if err != nil {
send(fmt.Sprintf("deldata: %s is not an ID", i), false)
return
}
if err := rtorrent.Delete(true, torrents[id]); err != nil {
logger.Print("deldata:", err)
send("deldata: "+err.Error(), false)
continue
}
send(fmt.Sprintf("Deleted with data: %s", torrents[id].Name), false)
}
}