Reimplement deletes and marking files as broken

This commit is contained in:
Ben Sarmiento
2024-01-29 22:28:27 +01:00
parent 1615c9e121
commit b505400f60
12 changed files with 64 additions and 112 deletions

View File

@@ -3,20 +3,20 @@ package torrent
import cmap "github.com/orcaman/concurrent-map/v2"
func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
var unselectedIDs []int
var deletedIDs []int
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if file.Link == "unselect" {
unselectedIDs = append(unselectedIDs, file.ID)
if file.IsDeleted {
deletedIDs = append(deletedIDs, file.ID)
}
})
if len(unselectedIDs) == torrent.SelectedFiles.Count() && len(unselectedIDs) > 0 {
if len(deletedIDs) == torrent.SelectedFiles.Count() && len(deletedIDs) > 0 {
return true
} else if len(unselectedIDs) > 0 {
} else if len(deletedIDs) > 0 {
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
info.SelectedFiles.IterCb(func(_ string, file *File) {
for _, unselectedID := range unselectedIDs {
if file.ID == unselectedID {
file.Link = "unselect"
for _, deletedID := range deletedIDs {
if file.ID == deletedID {
file.IsDeleted = true
break
}
}