do not overwrite info
This commit is contained in:
@@ -14,8 +14,20 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
|||||||
} else if len(unselectedIDs) > 0 {
|
} else if len(unselectedIDs) > 0 {
|
||||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
infoCache.Set(id, torrent)
|
info, _ := infoCache.Get(id)
|
||||||
t.writeTorrentToFile(id, torrent, false)
|
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
|
found := false
|
||||||
|
for _, unselectedID := range unselectedIDs {
|
||||||
|
if file.ID == unselectedID {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if found {
|
||||||
|
file.Link = "unselect"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.writeTorrentToFile(id, info, false)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,9 +208,9 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
|||||||
|
|
||||||
// the link can have the following values
|
// the link can have the following values
|
||||||
// 1. https://*** - the file is available
|
// 1. https://*** - the file is available
|
||||||
// 2. repair - the file is available but we need to repair it
|
// 2. repair - the link is there but we need to repair it
|
||||||
// 3. repairing - the file is being repaired
|
// 3. unselect - the file is deleted
|
||||||
// 4. unselect - the file is deleted
|
// 4. empty - the file is not available
|
||||||
mainTorrent.SelectedFiles = existing.SelectedFiles
|
mainTorrent.SelectedFiles = existing.SelectedFiles
|
||||||
toMerge.SelectedFiles.IterCb(func(filepath string, fileToMerge *File) {
|
toMerge.SelectedFiles.IterCb(func(filepath string, fileToMerge *File) {
|
||||||
// see if it already exists in the main torrent
|
// see if it already exists in the main torrent
|
||||||
@@ -219,7 +219,8 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
|||||||
mainTorrent.SelectedFiles.Set(filepath, fileToMerge)
|
mainTorrent.SelectedFiles.Set(filepath, fileToMerge)
|
||||||
} else if originalFile.Link != "unselect" {
|
} else if originalFile.Link != "unselect" {
|
||||||
// if it exists, compare the LatestAdded property and the link
|
// if it exists, compare the LatestAdded property and the link
|
||||||
if existing.LatestAdded < toMerge.LatestAdded && strings.HasPrefix(fileToMerge.Link, "http") {
|
if existing.LatestAdded < toMerge.LatestAdded {
|
||||||
|
// && strings.HasPrefix(fileToMerge.Link, "http")
|
||||||
// if torrentToMerge is more recent and its file has a link, update the main torrent's file
|
// if torrentToMerge is more recent and its file has a link, update the main torrent's file
|
||||||
mainTorrent.SelectedFiles.Set(filepath, fileToMerge)
|
mainTorrent.SelectedFiles.Set(filepath, fileToMerge)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,10 +102,28 @@ func (t *TorrentManager) repairAll() {
|
|||||||
|
|
||||||
func (t *TorrentManager) Repair(torrent *Torrent) {
|
func (t *TorrentManager) Repair(torrent *Torrent) {
|
||||||
// save the broken files to the file cache
|
// save the broken files to the file cache
|
||||||
|
var brokenFileIDs []int
|
||||||
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
|
if file.Link == "repair" {
|
||||||
|
brokenFileIDs = append(brokenFileIDs, file.ID)
|
||||||
|
}
|
||||||
|
})
|
||||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
infoCache.Set(id, torrent)
|
info, _ := infoCache.Get(id)
|
||||||
t.writeTorrentToFile(id, torrent, false)
|
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
|
found := false
|
||||||
|
for _, brokenFileID := range brokenFileIDs {
|
||||||
|
if file.ID == brokenFileID {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if found {
|
||||||
|
file.Link = "unselect"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.writeTorrentToFile(id, info, false)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
_ = t.workerPool.Submit(func() {
|
_ = t.workerPool.Submit(func() {
|
||||||
@@ -205,7 +223,6 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if file.Link == "repair" || file.Link == "" {
|
if file.Link == "repair" || file.Link == "" {
|
||||||
brokenFiles = append(brokenFiles, *file)
|
brokenFiles = append(brokenFiles, *file)
|
||||||
file.Link = "repairing"
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent))
|
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent))
|
||||||
@@ -370,7 +387,7 @@ func (t *TorrentManager) markAsUnfixable(torrent *Torrent) {
|
|||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
info, _ := infoCache.Get(id)
|
info, _ := infoCache.Get(id)
|
||||||
info.Unfixable = true
|
info.Unfixable = true
|
||||||
t.writeTorrentToFile(id, torrent, false)
|
t.writeTorrentToFile(id, info, false)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user