Skip to content

Commit

Permalink
skip invalid torrents when compacting db
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Jul 18, 2024
1 parent c7cf94b commit 6decbc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ func main() {
Name: "compact-database",
Usage: "rewrite database to save up space",
Action: handleCompactDatabase,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config,c",
Usage: "read config from `FILE`",
Value: "~/rain/config.yaml",
},
},
},
{
Name: "torrent",
Expand Down Expand Up @@ -547,6 +554,8 @@ func handleCompactDatabase(c *cli.Context) error {
return err
}
cfg.ResumeOnStartup = false
cfg.RPCEnabled = false
cfg.DHTEnabled = false
ses, err := torrent.NewSession(cfg)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions torrent/session_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func (s *Session) CompactDatabase(output string) error {
return err
}
for _, t := range s.torrents {
if t.torrent.info == nil {
s.log.Warningf("skipping torrent %s: info is nil", t.torrent.id)
continue
}
spec := &boltdbresumer.Spec{
InfoHash: t.torrent.InfoHash(),
Port: t.torrent.port,
Expand Down

0 comments on commit 6decbc4

Please sign in to comment.