Adjust file reads and writes

This commit is contained in:
Ben Sarmiento
2024-05-20 22:57:20 +02:00
parent a3a24124a8
commit d5dd9426ed
5 changed files with 22 additions and 34 deletions

View File

@@ -79,8 +79,6 @@ func (t *TorrentManager) refreshTorrents(isInitialRun bool) []string {
})
}
}
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)
// removed torrents
t.allAccessKeys.Difference(freshAccessKeys).Each(func(accessKey string) bool {
t.Delete(accessKey, false)
@@ -89,6 +87,8 @@ func (t *TorrentManager) refreshTorrents(isInitialRun bool) []string {
})
t.allAccessKeys.Append(freshAccessKeys.ToSlice()...)
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)
if t.Config.EnableRepair() {
if isInitialRun {
t.removeExpiredFixers(instances)
@@ -134,6 +134,13 @@ func (t *TorrentManager) StartRefreshJob() {
// getMoreInfo gets original name, size and files for a torrent
func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
diskTor := t.readTorrentFromFile(rdTorrent.Hash)
if diskTor != nil {
if diskInfo, ok := diskTor.Components[rdTorrent.ID]; ok && diskInfo.Progress == 100 {
return diskTor
}
}
info := t.readInfoFromFile(rdTorrent.ID)
if info == nil {
var err error
@@ -142,6 +149,9 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
t.log.Warnf("Cannot get info for id=%s: %v", rdTorrent.ID, err)
return nil
}
if info.Progress == 100 {
t.writeInfoToFile(info)
}
}
torrent := Torrent{
@@ -150,6 +160,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
Added: info.Added,
Hash: info.Hash,
}
// SelectedFiles is a subset of Files with only the selected ones
// it also has a Link field, which can be empty
// if it is empty, it means the file is no longer available
@@ -192,10 +203,6 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
}
torrent.Components = map[string]*realdebrid.TorrentInfo{rdTorrent.ID: info}
if info.Progress == 100 {
t.writeInfoToFile(info)
}
return &torrent
}