diff --git a/internal/dav/listing.go b/internal/dav/listing.go index 76601e9..c6ee254 100644 --- a/internal/dav/listing.go +++ b/internal/dav/listing.go @@ -112,6 +112,9 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) ([]byte, sort.Strings(filenames) for _, filename := range filenames { file, _ := tor.SelectedFiles.Get(filename) + if file == nil || file.Link == "" { + continue + } responses = append(responses, dav.File( filepath.Join(requestPath, filename), file.Bytes, diff --git a/internal/http/listing.go b/internal/http/listing.go index c725f28..3904bfb 100644 --- a/internal/http/listing.go +++ b/internal/http/listing.go @@ -96,7 +96,7 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string sort.Strings(filenames) for _, filename := range filenames { file, _ := tor.SelectedFiles.Get(filename) - if file.Link == "" { + if file == nil || file.Link == "" { // will be caught by torrent manager's repairAll // just skip it for now continue diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 0e65447..5980a36 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -260,13 +260,13 @@ func (t *TorrentManager) startRefreshJob() { noInfoCount := 0 allTorrents, _ := t.DirectoryMap.Get("__all__") - var retain []string + retain := make(map[string]bool) for info := range torrentsChan { if info == nil { noInfoCount++ continue } - retain = append(retain, info.AccessKey) + retain[info.AccessKey] = true if torrent, exists := allTorrents.Get(info.AccessKey); exists { mainTorrent := t.mergeToMain(torrent, info) allTorrents.Set(info.AccessKey, mainTorrent) @@ -305,25 +305,12 @@ func (t *TorrentManager) startRefreshJob() { }) // delete torrents that no longer exist - var toDelete []string - allTorrents.IterCb(func(_ string, torrent *Torrent) { - found := false - for _, accessKey := range retain { - if torrent.AccessKey == accessKey { - found = true - break - } + accessKeys := allTorrents.Keys() + for _, oldAccessKey := range accessKeys { + if _, ok := retain[oldAccessKey]; !ok { + allTorrents.Remove(oldAccessKey) } - if !found { - toDelete = append(toDelete, torrent.AccessKey) - } - }) - for _, accessKey := range toDelete { - t.DirectoryMap.IterCb(func(_ string, torrents cmap.ConcurrentMap[string, *Torrent]) { - torrents.Remove(accessKey) - }) } - // end delete torrents that no longer exist t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)