Merge pull request #646 from stakewinner00/master
don't print status info when running in the background
This commit is contained in:
commit
a5a9c42185
3 changed files with 43 additions and 0 deletions
9
src/cmds/restic/background.go
Normal file
9
src/cmds/restic/background.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// +build !linux
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
// IsProcessBackground should return true if it is running in the background or false if not
|
||||||
|
func IsProcessBackground() bool {
|
||||||
|
//TODO: Check if the process are running in the background in other OS than linux
|
||||||
|
return false
|
||||||
|
}
|
21
src/cmds/restic/background_linux.go
Normal file
21
src/cmds/restic/background_linux.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"restic/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IsProcessBackground returns true if it is running in the background or false if not
|
||||||
|
func IsProcessBackground() bool {
|
||||||
|
var pid int
|
||||||
|
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), syscall.TIOCGPGRP, uintptr(unsafe.Pointer(&pid)))
|
||||||
|
|
||||||
|
if err != 0 {
|
||||||
|
debug.Log("Can't check if we are in the background. Using default behaviour. Error: %s\n", err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return pid != syscall.Getpgrp()
|
||||||
|
}
|
|
@ -71,8 +71,13 @@ func newScanProgress(gopts GlobalOptions) *restic.Progress {
|
||||||
|
|
||||||
p := restic.NewProgress()
|
p := restic.NewProgress()
|
||||||
p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
|
if IsProcessBackground() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
PrintProgress("[%s] %d directories, %d files, %s", formatDuration(d), s.Dirs, s.Files, formatBytes(s.Bytes))
|
PrintProgress("[%s] %d directories, %d files, %s", formatDuration(d), s.Dirs, s.Files, formatBytes(s.Bytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
PrintProgress("scanned %d directories, %d files in %s\n", s.Dirs, s.Files, formatDuration(d))
|
PrintProgress("scanned %d directories, %d files in %s\n", s.Dirs, s.Files, formatDuration(d))
|
||||||
}
|
}
|
||||||
|
@ -91,6 +96,10 @@ func newArchiveProgress(gopts GlobalOptions, todo restic.Stat) *restic.Progress
|
||||||
itemsTodo := todo.Files + todo.Dirs
|
itemsTodo := todo.Files + todo.Dirs
|
||||||
|
|
||||||
archiveProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
archiveProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
|
if IsProcessBackground() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sec := uint64(d / time.Second)
|
sec := uint64(d / time.Second)
|
||||||
if todo.Bytes > 0 && sec > 0 && ticker {
|
if todo.Bytes > 0 && sec > 0 && ticker {
|
||||||
bps = s.Bytes / sec
|
bps = s.Bytes / sec
|
||||||
|
@ -144,6 +153,10 @@ func newArchiveStdinProgress(gopts GlobalOptions) *restic.Progress {
|
||||||
var bps uint64
|
var bps uint64
|
||||||
|
|
||||||
archiveProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
archiveProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
|
if IsProcessBackground() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sec := uint64(d / time.Second)
|
sec := uint64(d / time.Second)
|
||||||
if s.Bytes > 0 && sec > 0 && ticker {
|
if s.Bytes > 0 && sec > 0 && ticker {
|
||||||
bps = s.Bytes / sec
|
bps = s.Bytes / sec
|
||||||
|
|
Loading…
Reference in a new issue