Handle deletes better

This commit is contained in:
Ben Sarmiento
2023-12-02 03:09:58 +01:00
parent 1cb80e5047
commit a8e8bab853
2 changed files with 25 additions and 15 deletions

View File

@@ -155,6 +155,7 @@ func (t *TorrentManager) RefreshTorrents() {
oldTorrents.Set(info.AccessKey, mainTorrent)
}
}
t.log.Infof("Compiled into %d torrents, %d were missing info", oldTorrents.Count(), noInfoCount)
// removed
strset.Difference(t.accessKeySet, freshKeys).Each(func(accessKey string) bool {
t.Delete(accessKey, false, false)
@@ -170,7 +171,6 @@ func (t *TorrentManager) RefreshTorrents() {
t.checkForOtherDeletedTorrents()
// now we can build the directory responses
t.UpdateDirectoryResponsesCache()
t.log.Infof("Compiled into %d torrents, %d were missing info", oldTorrents.Count(), noInfoCount)
t.SetNewLatestState(t.getCurrentState())
@@ -557,20 +557,8 @@ func (t *TorrentManager) checkForOtherDeletedTorrents() {
var toDelete []string
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
allTorrents.IterCb(func(_ string, torrent *Torrent) {
unselected := 0
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if file.Link == "unselect" {
unselected++
}
})
if unselected == torrent.SelectedFiles.Count() && unselected > 0 {
t.log.Infof("Deleting %s", torrent.AccessKey)
if t.CheckDeletedState(torrent) {
toDelete = append(toDelete, torrent.AccessKey)
} else if unselected > 0 {
// save to file
for i := range torrent.Instances {
t.writeTorrentToFile(&torrent.Instances[i])
}
}
})
for _, accessKey := range toDelete {
@@ -578,6 +566,24 @@ func (t *TorrentManager) checkForOtherDeletedTorrents() {
}
}
func (t *TorrentManager) CheckDeletedState(torrent *Torrent) bool {
unselected := 0
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if file.Link == "unselect" {
unselected++
}
})
if unselected == torrent.SelectedFiles.Count() && unselected > 0 {
return true
} else if unselected > 0 {
// save to file
for i := range torrent.Instances {
t.writeTorrentToFile(&torrent.Instances[i])
}
}
return false
}
func (t *TorrentManager) Delete(accessKey string, deleteInRD bool, updateDirectoryResponses bool) {
if deleteInRD {
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)