Skip to content

Commit e661448

Browse files
authored
Fix travis build (#804)
1 parent d8f565f commit e661448

File tree

3 files changed

+150
-55
lines changed

3 files changed

+150
-55
lines changed

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ go:
55

66
go_import_path: stash.appscode.dev/stash
77

8+
cache:
9+
directories:
10+
- $HOME/.cache/go-build
11+
- $GOPATH/pkg/mod
12+
13+
env:
14+
global:
15+
- ARG_OS=linux
16+
- ARG_ARCH=amd64
17+
- RESTIC_VER="0.8.3"
18+
- NEW_RESTIC_VER="0.9.5"
19+
20+
before_install:
21+
- sudo apt-get -qq update
22+
- sudo apt-get install -y curl bzip2
23+
- curl -fsSL -o restic.bz2 https://github.com/restic/restic/releases/download/v${RESTIC_VER}/restic_${RESTIC_VER}_${ARG_OS}_${ARG_ARCH}.bz2
24+
- bzip2 -d restic.bz2
25+
- chmod +x restic
26+
- sudo mv restic /bin/restic
27+
- curl -fsSL -o restic_${NEW_RESTIC_VER}.bz2 https://github.com/restic/restic/releases/download/v${NEW_RESTIC_VER}/restic_${NEW_RESTIC_VER}_${ARG_OS}_${ARG_ARCH}.bz2
28+
- bzip2 -d restic_${NEW_RESTIC_VER}.bz2
29+
- chmod +x restic_${NEW_RESTIC_VER}
30+
- sudo mv restic_${NEW_RESTIC_VER} /bin/restic_${NEW_RESTIC_VER}
31+
832
install: true
933

1034
script:

pkg/restic/commands.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"os"
8+
"os/exec"
89
"path/filepath"
910
"strconv"
1011
"strings"
@@ -17,8 +18,6 @@ import (
1718

1819
const (
1920
ResticCMD = "/bin/restic_0.9.5"
20-
IONiceCMD = "/bin/ionice"
21-
NiceCMD = "/bin/nice"
2221
)
2322

2423
type Snapshot struct {
@@ -318,7 +317,14 @@ func (w *ResticWrapper) run(commands ...Command) ([]byte, error) {
318317
for _, cmd := range commands {
319318
if cmd.Name == ResticCMD {
320319
// first apply NiceSettings, then apply IONiceSettings
321-
cmd = w.applyIONiceSettings(w.applyNiceSettings(cmd))
320+
cmd, err = w.applyNiceSettings(cmd)
321+
if err != nil {
322+
return nil, err
323+
}
324+
cmd, err = w.applyIONiceSettings(cmd)
325+
if err != nil {
326+
return nil, err
327+
}
322328
}
323329
w.sh.Command(cmd.Name, cmd.Args...)
324330
}
@@ -339,9 +345,15 @@ func formatError(err error, stdErr string) error {
339345
return err
340346
}
341347

342-
func (w *ResticWrapper) applyIONiceSettings(oldCommand Command) Command {
348+
func (w *ResticWrapper) applyIONiceSettings(oldCommand Command) (Command, error) {
343349
if w.config.IONice == nil {
344-
return oldCommand
350+
return oldCommand, nil
351+
}
352+
353+
// detect "ionice" installation path
354+
IONiceCMD, err := exec.LookPath("ionice")
355+
if err != nil {
356+
return Command{}, err
345357
}
346358
newCommand := Command{
347359
Name: IONiceCMD,
@@ -358,12 +370,18 @@ func (w *ResticWrapper) applyIONiceSettings(oldCommand Command) Command {
358370
// append oldCommand as args of newCommand
359371
newCommand.Args = append(newCommand.Args, oldCommand.Name)
360372
newCommand.Args = append(newCommand.Args, oldCommand.Args...)
361-
return newCommand
373+
return newCommand, nil
362374
}
363375

364-
func (w *ResticWrapper) applyNiceSettings(oldCommand Command) Command {
376+
func (w *ResticWrapper) applyNiceSettings(oldCommand Command) (Command, error) {
365377
if w.config.Nice == nil {
366-
return oldCommand
378+
return oldCommand, nil
379+
}
380+
381+
// detect "nice" installation path
382+
NiceCMD, err := exec.LookPath("nice")
383+
if err != nil {
384+
return Command{}, err
367385
}
368386
newCommand := Command{
369387
Name: NiceCMD,
@@ -375,5 +393,5 @@ func (w *ResticWrapper) applyNiceSettings(oldCommand Command) Command {
375393
// append oldCommand as args of newCommand
376394
newCommand.Args = append(newCommand.Args, oldCommand.Name)
377395
newCommand.Args = append(newCommand.Args, oldCommand.Args...)
378-
return newCommand
396+
return newCommand, nil
379397
}

0 commit comments

Comments
 (0)