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

@@ -32,6 +32,10 @@ func HandleDeleteFile(directory, torrentName, fileName string, t *torrent.Torren
return fmt.Errorf("cannot find file %s", fileName)
}
file.Link = "unselect"
if t.CheckDeletedState(torrent) {
t.Delete(torrentName, true, true)
} else {
t.UpdateTorrentResponseCache(torrent)
}
return nil
}

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,6 +557,16 @@ func (t *TorrentManager) checkForOtherDeletedTorrents() {
var toDelete []string
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
allTorrents.IterCb(func(_ string, torrent *Torrent) {
if t.CheckDeletedState(torrent) {
toDelete = append(toDelete, torrent.AccessKey)
}
})
for _, accessKey := range toDelete {
t.Delete(accessKey, true, false)
}
}
func (t *TorrentManager) CheckDeletedState(torrent *Torrent) bool {
unselected := 0
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if file.Link == "unselect" {
@@ -564,18 +574,14 @@ func (t *TorrentManager) checkForOtherDeletedTorrents() {
}
})
if unselected == torrent.SelectedFiles.Count() && unselected > 0 {
t.log.Infof("Deleting %s", torrent.AccessKey)
toDelete = append(toDelete, torrent.AccessKey)
return true
} else if unselected > 0 {
// save to file
for i := range torrent.Instances {
t.writeTorrentToFile(&torrent.Instances[i])
}
}
})
for _, accessKey := range toDelete {
t.Delete(accessKey, true, false)
}
return false
}
func (t *TorrentManager) Delete(accessKey string, deleteInRD bool, updateDirectoryResponses bool) {