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)
|
||||
|
||||
if t, ok := c.torrents.Load(id); ok {
|
||||
err := c.client.DeleteTorrent(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = c.client.DeleteTorrent(id) // SKip error handling, we don't care if it fails
|
||||
c.torrents.Delete(id)
|
||||
c.torrentsNames.Delete(c.GetTorrentFolder(t.Torrent))
|
||||
c.removeFromDB(id)
|
||||
|
||||
@@ -131,6 +131,8 @@ func (c *Cache) ReInsertTorrent(torrent *types.Torrent) error {
|
||||
|
||||
oldID := torrent.Id
|
||||
|
||||
defer c.repairsInProgress.Delete(oldID)
|
||||
|
||||
// Submit the magnet to the debrid service
|
||||
torrent.Id = ""
|
||||
var err error
|
||||
@@ -143,8 +145,14 @@ func (c *Cache) ReInsertTorrent(torrent *types.Torrent) error {
|
||||
if torrent == nil || torrent.Id == "" {
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -152,6 +160,10 @@ func (c *Cache) ReInsertTorrent(torrent *types.Torrent) error {
|
||||
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
|
||||
addedOn, err := time.Parse(time.RFC3339, torrent.Added)
|
||||
if err != nil {
|
||||
@@ -164,7 +176,5 @@ func (c *Cache) ReInsertTorrent(torrent *types.Torrent) error {
|
||||
}
|
||||
c.setTorrent(ct)
|
||||
c.refreshListings()
|
||||
|
||||
c.repairsInProgress.Delete(oldID)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user