mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(actions): cross platform watch dir file handling (#458)
* chore: update deps * fix(actions): cross-platform file handling * fix(qbittorrent): unrelated failing test
This commit is contained in:
parent
8b96f29f37
commit
bbb8d2fe6e
22 changed files with 129 additions and 123 deletions
|
@ -3,7 +3,7 @@ package action
|
|||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
|
@ -123,7 +123,7 @@ func (s *service) delugeV1(client *domain.DownloadClient, action domain.Action,
|
|||
}
|
||||
}
|
||||
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
t, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ func (s *service) delugeV2(client *domain.DownloadClient, action domain.Action,
|
|||
}
|
||||
}
|
||||
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
t, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -23,7 +23,7 @@ func (s *service) execCmd(action domain.Action, release domain.Release) error {
|
|||
|
||||
// read the file into bytes we can then use in the macro
|
||||
if len(release.TorrentDataRawBytes) == 0 && release.TorrentTmpFile != "" {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
t, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package action
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
|
@ -38,7 +38,7 @@ func (s *service) rtorrent(action domain.Action, release domain.Release) ([]stri
|
|||
// create client
|
||||
rt := rtorrent.New(client.Host, true)
|
||||
|
||||
tmpFile, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
tmpFile, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
|
|
@ -4,10 +4,9 @@ import (
|
|||
"bytes"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -141,7 +140,7 @@ func (s *service) watchFolder(action domain.Action, release domain.Release) erro
|
|||
}
|
||||
|
||||
if len(release.TorrentDataRawBytes) == 0 {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
t, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
@ -166,12 +165,11 @@ func (s *service) watchFolder(action domain.Action, release domain.Release) erro
|
|||
}
|
||||
defer original.Close()
|
||||
|
||||
_, tmpFileName := path.Split(release.TorrentTmpFile)
|
||||
fullFileName := path.Join(watchFolderArgs, tmpFileName+".torrent")
|
||||
_, tmpFileName := filepath.Split(release.TorrentTmpFile)
|
||||
fullFileName := filepath.Join(watchFolderArgs, tmpFileName+".torrent")
|
||||
|
||||
// Create folder
|
||||
err = os.MkdirAll(watchFolderArgs, os.ModePerm)
|
||||
if err != nil {
|
||||
if err = os.MkdirAll(watchFolderArgs, os.ModePerm); err != nil {
|
||||
return errors.Wrap(err, "could not create new folders %v", fullFileName)
|
||||
}
|
||||
|
||||
|
@ -183,8 +181,7 @@ func (s *service) watchFolder(action domain.Action, release domain.Release) erro
|
|||
defer newFile.Close()
|
||||
|
||||
// Copy file
|
||||
_, err = io.Copy(newFile, original)
|
||||
if err != nil {
|
||||
if _, err := io.Copy(newFile, original); err != nil {
|
||||
return errors.Wrap(err, "could not copy file %v to watch folder", fullFileName)
|
||||
}
|
||||
|
||||
|
@ -203,7 +200,7 @@ func (s *service) webhook(action domain.Action, release domain.Release) error {
|
|||
|
||||
// if webhook data contains TorrentDataRawBytes, lets read the file into bytes we can then use in the macro
|
||||
if len(release.TorrentDataRawBytes) == 0 && strings.Contains(action.WebhookData, "TorrentDataRawBytes") {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
t, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue