Fix re-insertion
This commit is contained in:
@@ -626,10 +626,7 @@ func (c *Cache) DeleteTorrent(id string) error {
|
|||||||
c.logger.Info().Msgf("Deleting torrent %s", id)
|
c.logger.Info().Msgf("Deleting torrent %s", id)
|
||||||
|
|
||||||
if t, ok := c.torrents.Load(id); ok {
|
if t, ok := c.torrents.Load(id); ok {
|
||||||
err := c.client.DeleteTorrent(id)
|
_ = c.client.DeleteTorrent(id) // SKip error handling, we don't care if it fails
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.torrents.Delete(id)
|
c.torrents.Delete(id)
|
||||||
c.torrentsNames.Delete(c.GetTorrentFolder(t.Torrent))
|
c.torrentsNames.Delete(c.GetTorrentFolder(t.Torrent))
|
||||||
c.removeFromDB(id)
|
c.removeFromDB(id)
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ func (c *Cache) ReInsertTorrent(torrent *types.Torrent) error {
|
|||||||
|
|
||||||
oldID := torrent.Id
|
oldID := torrent.Id
|
||||||
|
|
||||||
|
defer c.repairsInProgress.Delete(oldID)
|
||||||
|
|
||||||
// Submit the magnet to the debrid service
|
// Submit the magnet to the debrid service
|
||||||
torrent.Id = ""
|
torrent.Id = ""
|
||||||
var err error
|
var err error
|
||||||
@@ -143,8 +145,14 @@ func (c *Cache) ReInsertTorrent(torrent *types.Torrent) error {
|
|||||||
if torrent == nil || torrent.Id == "" {
|
if torrent == nil || torrent.Id == "" {
|
||||||
return fmt.Errorf("failed to submit magnet: empty torrent")
|
return fmt.Errorf("failed to submit magnet: empty torrent")
|
||||||
}
|
}
|
||||||
|
torrent.DownloadUncached = false // Set to false, avoid re-downloading
|
||||||
torrent, err = c.client.CheckStatus(torrent, true)
|
torrent, err = c.client.CheckStatus(torrent, true)
|
||||||
if err != nil {
|
if err != nil && torrent != nil {
|
||||||
|
// Torrent is likely in progress
|
||||||
|
// Delete the old and new torrent
|
||||||
|
_ = c.DeleteTorrent(oldID)
|
||||||
|
_ = c.DeleteTorrent(torrent.Id)
|
||||||
|
|
||||||
return fmt.Errorf("failed to check status: %w", err)
|
return fmt.Errorf("failed to check status: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +160,10 @@ func (c *Cache) ReInsertTorrent(torrent *types.Torrent) error {
|
|||||||
return fmt.Errorf("failed to delete old torrent: %w", err)
|
return fmt.Errorf("failed to delete old torrent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if torrent == nil {
|
||||||
|
return fmt.Errorf("failed to check status: empty torrent")
|
||||||
|
}
|
||||||
|
|
||||||
// Update the torrent in the cache
|
// Update the torrent in the cache
|
||||||
addedOn, err := time.Parse(time.RFC3339, torrent.Added)
|
addedOn, err := time.Parse(time.RFC3339, torrent.Added)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -164,7 +176,5 @@ func (c *Cache) ReInsertTorrent(torrent *types.Torrent) error {
|
|||||||
}
|
}
|
||||||
c.setTorrent(ct)
|
c.setTorrent(ct)
|
||||||
c.refreshListings()
|
c.refreshListings()
|
||||||
|
|
||||||
c.repairsInProgress.Delete(oldID)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user