Remove immediate bin

This commit is contained in:
Ben Adrian Sarmiento
2024-06-18 23:43:31 +02:00
parent 34a7d6a432
commit acc9b69b5a
8 changed files with 58 additions and 87 deletions

View File

@@ -37,8 +37,7 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
idx := i
t.workerPool.Submit(func() {
defer wg.Done()
if t.binImmediately(instances[idx].ID) ||
t.binOnceDoneErrorCheck(instances[idx].ID, instances[idx].Status) ||
if t.binOnceDoneErrorCheck(instances[idx].ID, instances[idx].Status) ||
instances[idx].Progress != 100 {
mergeChan <- nil
return
@@ -55,7 +54,7 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
allTorrents.Set(accessKey, torrent)
t.writeTorrentToFile(torrent)
t.assignDirectory(torrent, !initialRun)
} else if !mainTorrent.DownloadedIDs.Contains(tInfo.ID) {
} else if !mainTorrent.DownloadedIDs.ContainsOne(tInfo.ID) {
forMerging = torrent
}
@@ -98,20 +97,21 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
t.log.Infof("Compiled into %d unique torrents", allTorrents.Count())
// delete info files that are no longer present
// it also runs binOnceDone (needed for cleanup every refresh)
t.getInfoFiles().Each(func(path string) bool {
path = filepath.Base(path)
torrentID := strings.TrimSuffix(path, ".zurginfo")
// if binOnceDone returns true, it means the info file is deleted
// if false, then we check if it's one of the torrents we just fetched
// if not (both are false), then we delete the info file
if !t.binOnceDone(torrentID, false) && !freshIDs.Contains(torrentID) {
if !t.binOnceDone(torrentID, false) && !freshIDs.ContainsOne(torrentID) {
t.deleteInfoFile(torrentID)
}
return false
})
// cleans up DownloadedIDs field of all torrents
t.workerPool.Submit(func() {
// update DownloadedIDs field of torrents
allTorrents.IterCb(func(accessKey string, torrent *Torrent) {
deletedIDs := torrent.DownloadedIDs.Difference(freshIDs)
if deletedIDs.Cardinality() > 0 {
@@ -167,7 +167,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *realdebrid.T
func (t *TorrentManager) convertToTorrent(info *realdebrid.TorrentInfo) *Torrent {
torrent := t.readTorrentFromFile("data/" + info.Hash + ".zurgtorrent")
if torrent != nil && torrent.DownloadedIDs.Contains(info.ID) {
if torrent != nil && torrent.DownloadedIDs.ContainsOne(info.ID) {
return torrent
}
@@ -189,7 +189,7 @@ func (t *TorrentManager) convertToTorrent(info *realdebrid.TorrentInfo) *Torrent
var selectedFiles []*File
for _, file := range info.Files {
filename := filepath.Base(file.Path)
if allFilenames.Contains(filename) {
if allFilenames.ContainsOne(filename) {
dupeFilenames.Add(filename)
} else {
allFilenames.Add(filename)
@@ -228,7 +228,7 @@ func (t *TorrentManager) convertToTorrent(info *realdebrid.TorrentInfo) *Torrent
for _, file := range selectedFiles {
baseFilename := t.GetPath(file)
// todo better handling of duplicate filenames
if dupeFilenames.Contains(baseFilename) {
if dupeFilenames.ContainsOne(baseFilename) {
extension := filepath.Ext(baseFilename)
filenameNoExt := strings.TrimSuffix(baseFilename, extension)
newName := fmt.Sprintf("%s (%d)%s", filenameNoExt, file.ID, extension)