5
5
"fmt"
6
6
"io"
7
7
"os"
8
+ "os/exec"
8
9
"path/filepath"
9
10
"strconv"
10
11
"strings"
@@ -17,8 +18,6 @@ import (
17
18
18
19
const (
19
20
ResticCMD = "/bin/restic_0.9.5"
20
- IONiceCMD = "/bin/ionice"
21
- NiceCMD = "/bin/nice"
22
21
)
23
22
24
23
type Snapshot struct {
@@ -318,7 +317,14 @@ func (w *ResticWrapper) run(commands ...Command) ([]byte, error) {
318
317
for _ , cmd := range commands {
319
318
if cmd .Name == ResticCMD {
320
319
// 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
+ }
322
328
}
323
329
w .sh .Command (cmd .Name , cmd .Args ... )
324
330
}
@@ -339,9 +345,15 @@ func formatError(err error, stdErr string) error {
339
345
return err
340
346
}
341
347
342
- func (w * ResticWrapper ) applyIONiceSettings (oldCommand Command ) Command {
348
+ func (w * ResticWrapper ) applyIONiceSettings (oldCommand Command ) ( Command , error ) {
343
349
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
345
357
}
346
358
newCommand := Command {
347
359
Name : IONiceCMD ,
@@ -358,12 +370,18 @@ func (w *ResticWrapper) applyIONiceSettings(oldCommand Command) Command {
358
370
// append oldCommand as args of newCommand
359
371
newCommand .Args = append (newCommand .Args , oldCommand .Name )
360
372
newCommand .Args = append (newCommand .Args , oldCommand .Args ... )
361
- return newCommand
373
+ return newCommand , nil
362
374
}
363
375
364
- func (w * ResticWrapper ) applyNiceSettings (oldCommand Command ) Command {
376
+ func (w * ResticWrapper ) applyNiceSettings (oldCommand Command ) ( Command , error ) {
365
377
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
367
385
}
368
386
newCommand := Command {
369
387
Name : NiceCMD ,
@@ -375,5 +393,5 @@ func (w *ResticWrapper) applyNiceSettings(oldCommand Command) Command {
375
393
// append oldCommand as args of newCommand
376
394
newCommand .Args = append (newCommand .Args , oldCommand .Name )
377
395
newCommand .Args = append (newCommand .Args , oldCommand .Args ... )
378
- return newCommand
396
+ return newCommand , nil
379
397
}
0 commit comments