Bin error checks

This commit is contained in:
Ben Sarmiento
2024-05-27 06:25:55 +02:00
parent fb37fd69e1
commit ac89f53896
4 changed files with 55 additions and 81 deletions

View File

@@ -32,44 +32,25 @@ func (t *TorrentManager) refreshTorrents() []string {
freshIDs := mapset.NewSet[string]()
freshAccessKeys := mapset.NewSet[string]()
t.getTorrentFiles("dump").Each(func(filePath string) bool {
cachedAccessKeys := mapset.NewSet[string]()
t.getTorrentFiles("data").Each(func(filePath string) bool {
torrent := t.readTorrentFromFile(filePath)
if torrent != nil {
accessKey := t.GetKey(torrent)
if !allTorrents.Has(accessKey) {
t.log.Debugf("Loading dumped torrent %s", accessKey)
allTorrents.Set(accessKey, torrent)
t.assignDirectory(torrent, func(directory string) {
listing, _ := t.DirectoryMap.Get(directory)
listing.Set(accessKey, torrent)
// note that we're not adding it to updatedPaths
})
}
freshAccessKeys.Add(accessKey) // to prevent being deleted
allTorrents.Set(t.GetKey(torrent), torrent)
filename := filepath.Base(filePath)
cachedAccessKeys.Add(strings.TrimSuffix(filename, ".zurgtorrent"))
}
return false
})
cachedAccessKeys := mapset.NewSet[string]()
t.getTorrentFiles("data").Each(func(path string) bool {
path = filepath.Base(path)
cachedAccessKeys.Add(strings.TrimSuffix(path, ".zurgtorrent"))
return false
})
for i := range instances {
wg.Add(1)
idx := i
_ = t.workerPool.Submit(func() {
defer wg.Done()
if t.binImmediately(instances[idx].ID) {
// t.log.Debugf("Skipping trashed torrent %s (id=%s)", instances[idx].Name, instances[idx].ID)
mergeChan <- nil
return
}
if instances[idx].Progress != 100 {
// t.log.Debugf("Skipping incomplete torrent %s (id=%s)", instances[idx].Name, instances[idx].ID)
if t.binImmediately(instances[idx].ID) ||
t.binOnceDoneErrorCheck(instances[idx].ID, instances[idx].Status) ||
instances[idx].Progress != 100 {
mergeChan <- nil
return
}