mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(releases): create custom TEMPDIR if not exists (#1428)
* fix(releases): create custom TEMPDIR if not exists * fix(releases): create temp err handling
This commit is contained in:
parent
2bf5993f05
commit
f619501d0d
1 changed files with 17 additions and 2 deletions
|
@ -451,10 +451,25 @@ func (r *Release) downloadTorrentFile(ctx context.Context) error {
|
||||||
req.Header.Set("Cookie", r.RawCookie)
|
req.Header.Set("Cookie", r.RawCookie)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmpFilePattern := "autobrr-"
|
||||||
|
tmpDir := os.TempDir()
|
||||||
|
|
||||||
// Create tmp file
|
// Create tmp file
|
||||||
tmpFile, err := os.CreateTemp("", "autobrr-")
|
tmpFile, err := os.CreateTemp(tmpDir, tmpFilePattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error creating tmp file")
|
// inverse the err check to make it a bit cleaner
|
||||||
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return errors.Wrap(err, "error creating tmp file")
|
||||||
|
}
|
||||||
|
|
||||||
|
if mkdirErr := os.MkdirAll(tmpDir, os.ModePerm); mkdirErr != nil {
|
||||||
|
return errors.Wrap(mkdirErr, "could not create TMP dir: %s", tmpDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpFile, err = os.CreateTemp(tmpDir, tmpFilePattern)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error creating tmp file in: %s", tmpDir)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
defer tmpFile.Close()
|
defer tmpFile.Close()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue