Skip to content

Commit

Permalink
Fix travis build (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha authored May 24, 2019
1 parent d8f565f commit e661448
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 55 deletions.
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ go:

go_import_path: stash.appscode.dev/stash

cache:
directories:
- $HOME/.cache/go-build
- $GOPATH/pkg/mod

env:
global:
- ARG_OS=linux
- ARG_ARCH=amd64
- RESTIC_VER="0.8.3"
- NEW_RESTIC_VER="0.9.5"

before_install:
- sudo apt-get -qq update
- sudo apt-get install -y curl bzip2
- curl -fsSL -o restic.bz2 https://github.com/restic/restic/releases/download/v${RESTIC_VER}/restic_${RESTIC_VER}_${ARG_OS}_${ARG_ARCH}.bz2
- bzip2 -d restic.bz2
- chmod +x restic
- sudo mv restic /bin/restic
- 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
- bzip2 -d restic_${NEW_RESTIC_VER}.bz2
- chmod +x restic_${NEW_RESTIC_VER}
- sudo mv restic_${NEW_RESTIC_VER} /bin/restic_${NEW_RESTIC_VER}

install: true

script:
Expand Down
36 changes: 27 additions & 9 deletions pkg/restic/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
Expand All @@ -17,8 +18,6 @@ import (

const (
ResticCMD = "/bin/restic_0.9.5"
IONiceCMD = "/bin/ionice"
NiceCMD = "/bin/nice"
)

type Snapshot struct {
Expand Down Expand Up @@ -318,7 +317,14 @@ func (w *ResticWrapper) run(commands ...Command) ([]byte, error) {
for _, cmd := range commands {
if cmd.Name == ResticCMD {
// first apply NiceSettings, then apply IONiceSettings
cmd = w.applyIONiceSettings(w.applyNiceSettings(cmd))
cmd, err = w.applyNiceSettings(cmd)
if err != nil {
return nil, err
}
cmd, err = w.applyIONiceSettings(cmd)
if err != nil {
return nil, err
}
}
w.sh.Command(cmd.Name, cmd.Args...)
}
Expand All @@ -339,9 +345,15 @@ func formatError(err error, stdErr string) error {
return err
}

func (w *ResticWrapper) applyIONiceSettings(oldCommand Command) Command {
func (w *ResticWrapper) applyIONiceSettings(oldCommand Command) (Command, error) {
if w.config.IONice == nil {
return oldCommand
return oldCommand, nil
}

// detect "ionice" installation path
IONiceCMD, err := exec.LookPath("ionice")
if err != nil {
return Command{}, err
}
newCommand := Command{
Name: IONiceCMD,
Expand All @@ -358,12 +370,18 @@ func (w *ResticWrapper) applyIONiceSettings(oldCommand Command) Command {
// append oldCommand as args of newCommand
newCommand.Args = append(newCommand.Args, oldCommand.Name)
newCommand.Args = append(newCommand.Args, oldCommand.Args...)
return newCommand
return newCommand, nil
}

func (w *ResticWrapper) applyNiceSettings(oldCommand Command) Command {
func (w *ResticWrapper) applyNiceSettings(oldCommand Command) (Command, error) {
if w.config.Nice == nil {
return oldCommand
return oldCommand, nil
}

// detect "nice" installation path
NiceCMD, err := exec.LookPath("nice")
if err != nil {
return Command{}, err
}
newCommand := Command{
Name: NiceCMD,
Expand All @@ -375,5 +393,5 @@ func (w *ResticWrapper) applyNiceSettings(oldCommand Command) Command {
// append oldCommand as args of newCommand
newCommand.Args = append(newCommand.Args, oldCommand.Name)
newCommand.Args = append(newCommand.Args, oldCommand.Args...)
return newCommand
return newCommand, nil
}
Loading

0 comments on commit e661448

Please sign in to comment.