Access key computation without clearing data
This commit is contained in:
@@ -96,7 +96,7 @@ func (t *TorrentManager) repairAll() {
|
||||
t.log.Debugf("Found %d broken torrents to repair in total", len(toRepair))
|
||||
for i := range toRepair {
|
||||
torrent := toRepair[i]
|
||||
t.log.Infof("Repairing %s", torrent.AccessKey)
|
||||
t.log.Infof("Repairing %s", t.GetKey(torrent))
|
||||
t.repair(torrent)
|
||||
}
|
||||
}
|
||||
@@ -105,19 +105,19 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
|
||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||
infoCache.Set(id, torrent)
|
||||
t.writeTorrentToFile(id, torrent)
|
||||
t.writeTorrentToFile(id, torrent, false)
|
||||
return false
|
||||
})
|
||||
_ = t.repairWorker.Submit(func() {
|
||||
t.log.Infof("Repairing torrent %s", torrent.AccessKey)
|
||||
t.log.Infof("Repairing torrent %s", t.GetKey(torrent))
|
||||
t.repair(torrent)
|
||||
t.log.Infof("Finished repairing torrent %s", torrent.AccessKey)
|
||||
t.log.Infof("Finished repairing torrent %s", t.GetKey(torrent))
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
if torrent.AnyInProgress() {
|
||||
t.log.Infof("Torrent %s is in progress, skipping repair until download is done", torrent.AccessKey)
|
||||
t.log.Infof("Torrent %s is in progress, skipping repair until download is done", t.GetKey(torrent))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -129,18 +129,18 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
|
||||
if torrent.OlderThanDuration(EXPIRED_LINK_TOLERANCE_HOURS * time.Hour) {
|
||||
// first solution: reinsert with same selection
|
||||
t.log.Infof("Torrent %s is older than %d hours, reinserting it", torrent.AccessKey, EXPIRED_LINK_TOLERANCE_HOURS)
|
||||
t.log.Infof("Torrent %s is older than %d hours, reinserting it", t.GetKey(torrent), EXPIRED_LINK_TOLERANCE_HOURS)
|
||||
if t.reinsertTorrent(torrent, "") {
|
||||
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
|
||||
t.log.Infof("Successfully downloaded torrent %s to repair it", t.GetKey(torrent))
|
||||
return
|
||||
} else if torrent.Unfixable {
|
||||
t.log.Warnf("Cannot repair torrent %s", torrent.AccessKey)
|
||||
t.log.Warnf("Cannot repair torrent %s", t.GetKey(torrent))
|
||||
return
|
||||
} else {
|
||||
t.log.Warnf("Failed to repair by reinserting torrent %s, will only redownload broken files...", torrent.AccessKey)
|
||||
t.log.Warnf("Failed to repair by reinserting torrent %s, will only redownload broken files...", t.GetKey(torrent))
|
||||
}
|
||||
} else {
|
||||
t.log.Warnf("Torrent %s is not older than %d hours to be repaired by reinsertion, will only redownload broken files...", torrent.AccessKey, EXPIRED_LINK_TOLERANCE_HOURS)
|
||||
t.log.Warnf("Torrent %s is not older than %d hours to be repaired by reinsertion, will only redownload broken files...", t.GetKey(torrent), EXPIRED_LINK_TOLERANCE_HOURS)
|
||||
}
|
||||
|
||||
// sleep for 30 seconds to let the torrent accumulate more broken files if scanning
|
||||
@@ -174,12 +174,12 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
})
|
||||
|
||||
if assignedCount > 0 {
|
||||
t.log.Infof("Assigned %d links to selected files for torrent %s", assignedCount, torrent.AccessKey)
|
||||
t.log.Infof("Assigned %d links to selected files for torrent %s", assignedCount, t.GetKey(torrent))
|
||||
} else if rarCount > 0 {
|
||||
// this is a rar'ed torrent, nothing we can do
|
||||
if t.Config.ShouldDeleteRarFiles() {
|
||||
t.log.Warnf("Torrent %s is rar'ed and we cannot repair it, deleting it as configured", torrent.AccessKey)
|
||||
t.Delete(torrent.AccessKey, true)
|
||||
t.log.Warnf("Torrent %s is rar'ed and we cannot repair it, deleting it as configured", t.GetKey(torrent))
|
||||
t.Delete(t.GetKey(torrent), true)
|
||||
} else {
|
||||
for _, unassigned := range unassignedDownloads {
|
||||
newFile := &File{
|
||||
@@ -208,14 +208,14 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
file.Link = "repairing"
|
||||
}
|
||||
})
|
||||
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), torrent.AccessKey)
|
||||
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent))
|
||||
|
||||
if len(brokenFiles) == 1 && torrent.SelectedFiles.Count() > 2 {
|
||||
// if we download a single file, it will be named differently
|
||||
// so we need to download 1 extra file to preserve the name
|
||||
// this is only relevant if we enable retain_rd_torrent_name
|
||||
// add the first file link encountered with a prefix of http
|
||||
t.log.Debugf("Torrent %s has only 1 broken file, adding 1 extra file to preserve the name", torrent.AccessKey)
|
||||
t.log.Debugf("Torrent %s has only 1 broken file, adding 1 extra file to preserve the name", t.GetKey(torrent))
|
||||
for _, file := range torrent.SelectedFiles.Items() {
|
||||
if strings.HasPrefix(file.Link, "http") {
|
||||
brokenFiles = append(brokenFiles, *file)
|
||||
@@ -225,15 +225,15 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
}
|
||||
|
||||
if len(brokenFiles) > 0 {
|
||||
t.log.Infof("Redownloading %dof%d files for torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), torrent.AccessKey)
|
||||
t.log.Infof("Redownloading %dof%d files for torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||
brokenFileIDs := strings.Join(getFileIDs(brokenFiles), ",")
|
||||
if t.reinsertTorrent(torrent, brokenFileIDs) {
|
||||
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
|
||||
t.log.Infof("Successfully downloaded torrent %s to repair it", t.GetKey(torrent))
|
||||
} else {
|
||||
t.log.Warnf("Cannot repair torrent %s", torrent.AccessKey)
|
||||
t.log.Warnf("Cannot repair torrent %s", t.GetKey(torrent))
|
||||
}
|
||||
} else {
|
||||
t.log.Warnf("Torrent %s has no broken files to repair", torrent.AccessKey)
|
||||
t.log.Warnf("Torrent %s has no broken files to repair", t.GetKey(torrent))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,22 +356,22 @@ func (t *TorrentManager) canCapacityHandle() bool {
|
||||
}
|
||||
|
||||
func (t *TorrentManager) markAsUnplayable(torrent *Torrent) {
|
||||
t.log.Warnf("Marking torrent %s as unplayable", torrent.AccessKey)
|
||||
t.log.Warnf("Marking torrent %s as unplayable", t.GetKey(torrent))
|
||||
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
||||
torrents.Remove(torrent.AccessKey)
|
||||
torrents.Remove(t.GetKey(torrent))
|
||||
})
|
||||
torrents, _ := t.DirectoryMap.Get(config.UNPLAYABLE_TORRENTS)
|
||||
torrents.Set(torrent.AccessKey, torrent)
|
||||
torrents.Set(t.GetKey(torrent), torrent)
|
||||
}
|
||||
|
||||
func (t *TorrentManager) markAsUnfixable(torrent *Torrent) {
|
||||
t.log.Warnf("Marking torrent %s as unfixable", torrent.AccessKey)
|
||||
t.log.Warnf("Marking torrent %s as unfixable", t.GetKey(torrent))
|
||||
torrent.Unfixable = true
|
||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||
info, _ := infoCache.Get(id)
|
||||
info.Unfixable = true
|
||||
t.writeTorrentToFile(id, torrent)
|
||||
t.writeTorrentToFile(id, torrent, false)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user