Juggle the test to the right place, call it also while saving config to be consistent
This commit is contained in:
@@ -281,13 +281,18 @@ func (dl *Download) Begin() {
|
||||
cmdSlice = append(cmdSlice, dl.Url)
|
||||
}
|
||||
|
||||
dl.Log = append(dl.Log, fmt.Sprintf("executing: %s with args: %s", dl.DownloadProfile.Command, strings.Join(cmdSlice, " ")))
|
||||
|
||||
cmdPath, err := absPathToExecutable(dl.DownloadProfile.Command)
|
||||
cmdPath, err := config.AbsPathToExecutable(dl.DownloadProfile.Command)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
dl.State = STATE_FAILED
|
||||
dl.Finished = true
|
||||
dl.FinishedTS = time.Now()
|
||||
dl.Log = append(dl.Log, fmt.Sprintf("error finding executable for downloader: %s", err.Error()))
|
||||
dl.Lock.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
dl.Log = append(dl.Log, fmt.Sprintf("executing: %s (%s) with args: %s", dl.DownloadProfile.Command, cmdPath, strings.Join(cmdSlice, " ")))
|
||||
|
||||
cmd := exec.Command(cmdPath, cmdSlice...)
|
||||
cmd.Dir = dl.Config.Server.DownloadPath
|
||||
log.Printf("Executing command executable: %s) in %s", cmdPath, dl.Config.Server.DownloadPath)
|
||||
@@ -299,7 +304,6 @@ func (dl *Download) Begin() {
|
||||
dl.FinishedTS = time.Now()
|
||||
dl.Log = append(dl.Log, fmt.Sprintf("error setting up stdout pipe: %v", err))
|
||||
dl.Lock.Unlock()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -373,28 +377,6 @@ func (dl *Download) Begin() {
|
||||
dl.Lock.Unlock()
|
||||
}
|
||||
|
||||
func absPathToExecutable(cmd string) (string, error) {
|
||||
|
||||
pathCmd, err := exec.LookPath(cmd)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not LookPath '%s': %w", cmd, err)
|
||||
}
|
||||
|
||||
execAbsolutePath, err := filepath.Abs(pathCmd)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not get absolute path to '%s': %w", cmd, err)
|
||||
}
|
||||
fi, err := os.Stat(execAbsolutePath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not get stat '%s': %w", cmd, err)
|
||||
}
|
||||
if !fi.Mode().IsRegular() {
|
||||
return "", fmt.Errorf("'%s' is not a regular file: %w", cmd, err)
|
||||
}
|
||||
|
||||
return execAbsolutePath, nil
|
||||
}
|
||||
|
||||
// updateDownload updates the download based on data from the reader. Expects the
|
||||
// Download to be unlocked.
|
||||
func (dl *Download) updateDownload(r io.Reader) {
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package download
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tardisx/gropple/config"
|
||||
)
|
||||
|
||||
@@ -364,41 +360,3 @@ Deleting original file The Greatest Shot In Television [2WoDQBhJCVQ].f140.m4a (p
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestLookForExecutable(t *testing.T) {
|
||||
cmdPath, err := exec.LookPath("sleep")
|
||||
if err != nil {
|
||||
t.Errorf("cannot run this test without knowing about sleep: %s", err)
|
||||
t.FailNow()
|
||||
}
|
||||
cmdDir := filepath.Dir(cmdPath)
|
||||
|
||||
cmd := "sleep"
|
||||
path, err := absPathToExecutable(cmd)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, cmdPath, path)
|
||||
}
|
||||
|
||||
cmd = cmdPath
|
||||
path, err = absPathToExecutable(cmd)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, cmdPath, path)
|
||||
}
|
||||
|
||||
cmd = "../../../../../../../../.." + cmdPath
|
||||
path, err = absPathToExecutable(cmd)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, cmdPath, path)
|
||||
}
|
||||
cmd = "./sleep"
|
||||
_, err = absPathToExecutable(cmd)
|
||||
assert.Error(t, err)
|
||||
|
||||
os.Chdir(cmdDir)
|
||||
cmd = "./sleep"
|
||||
path, err = absPathToExecutable(cmd)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, cmdPath, path)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user