forked from TrueCloudLab/restic
Enable the use of context
in restic
Set up a cancelble context in global options, hook it into the ctrl-C handler for proper cancel propegation. Bump up minimal requirement for Go to version 1.7 in documentation and test-build files.
This commit is contained in:
parent
3eaaa0f286
commit
b4526c4e6e
7 changed files with 15 additions and 7 deletions
|
@ -2,7 +2,6 @@ language: go
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.6.4
|
|
||||||
- 1.7.5
|
- 1.7.5
|
||||||
- 1.8
|
- 1.8
|
||||||
- tip
|
- tip
|
||||||
|
@ -17,8 +16,6 @@ env:
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
exclude:
|
exclude:
|
||||||
- os: osx
|
|
||||||
go: 1.6.4
|
|
||||||
- os: osx
|
- os: osx
|
||||||
go: 1.7.5
|
go: 1.7.5
|
||||||
- os: osx
|
- os: osx
|
||||||
|
|
|
@ -77,7 +77,7 @@ Just clone the repository, `cd` to it and run `gb build` to build the binary:
|
||||||
[...]
|
[...]
|
||||||
$ bin/restic version
|
$ bin/restic version
|
||||||
restic compiled manually
|
restic compiled manually
|
||||||
compiled at unknown time with go1.6
|
compiled at unknown time with go1.7
|
||||||
|
|
||||||
The following commands can be used to run all the tests:
|
The following commands can be used to run all the tests:
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ You can download the latest pre-compiled binary from the [restic release page](h
|
||||||
Build restic
|
Build restic
|
||||||
============
|
============
|
||||||
|
|
||||||
Install Go/Golang (at least version 1.6), then run `go run build.go`,
|
Install Go/Golang (at least version 1.7), then run `go run build.go`,
|
||||||
afterwards you'll find the binary in the current directory:
|
afterwards you'll find the binary in the current directory:
|
||||||
|
|
||||||
$ go run build.go
|
$ go run build.go
|
||||||
|
|
2
Vagrantfile
vendored
2
Vagrantfile
vendored
|
@ -1,7 +1,7 @@
|
||||||
# -*- mode: ruby -*-
|
# -*- mode: ruby -*-
|
||||||
# vi: set ft=ruby :
|
# vi: set ft=ruby :
|
||||||
|
|
||||||
GO_VERSION = '1.6'
|
GO_VERSION = '1.7'
|
||||||
|
|
||||||
def packages_freebsd
|
def packages_freebsd
|
||||||
return <<-EOF
|
return <<-EOF
|
||||||
|
|
|
@ -27,7 +27,7 @@ $ pacaur -S restic-git
|
||||||
|
|
||||||
# Building restic
|
# Building restic
|
||||||
|
|
||||||
restic is written in the Go programming language and you need at least Go version 1.6.
|
restic is written in the Go programming language and you need at least Go version 1.7.
|
||||||
Building restic may also work with older versions of Go, but that's not supported.
|
Building restic may also work with older versions of Go, but that's not supported.
|
||||||
See the [Getting started](https://golang.org/doc/install) guide of the Go project for
|
See the [Getting started](https://golang.org/doc/install) guide of the Go project for
|
||||||
instructions how to install Go.
|
instructions how to install Go.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -33,6 +34,7 @@ type GlobalOptions struct {
|
||||||
NoLock bool
|
NoLock bool
|
||||||
JSON bool
|
JSON bool
|
||||||
|
|
||||||
|
ctx context.Context
|
||||||
password string
|
password string
|
||||||
stdout io.Writer
|
stdout io.Writer
|
||||||
stderr io.Writer
|
stderr io.Writer
|
||||||
|
@ -49,6 +51,13 @@ func init() {
|
||||||
globalOptions.password = pw
|
globalOptions.password = pw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cancel context.CancelFunc
|
||||||
|
globalOptions.ctx, cancel = context.WithCancel(context.Background())
|
||||||
|
AddCleanupHandler(func() error {
|
||||||
|
cancel()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
f := cmdRoot.PersistentFlags()
|
f := cmdRoot.PersistentFlags()
|
||||||
f.StringVarP(&globalOptions.Repo, "repo", "r", os.Getenv("RESTIC_REPOSITORY"), "repository to backup to or restore from (default: $RESTIC_REPOSITORY)")
|
f.StringVarP(&globalOptions.Repo, "repo", "r", os.Getenv("RESTIC_REPOSITORY"), "repository to backup to or restore from (default: $RESTIC_REPOSITORY)")
|
||||||
f.StringVarP(&globalOptions.PasswordFile, "password-file", "p", "", "read the repository password from a file")
|
f.StringVarP(&globalOptions.PasswordFile, "password-file", "p", "", "read the repository password from a file")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -194,6 +195,7 @@ func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions))
|
||||||
gopts := GlobalOptions{
|
gopts := GlobalOptions{
|
||||||
Repo: env.repo,
|
Repo: env.repo,
|
||||||
Quiet: true,
|
Quiet: true,
|
||||||
|
ctx: context.Background(),
|
||||||
password: TestPassword,
|
password: TestPassword,
|
||||||
stdout: os.Stdout,
|
stdout: os.Stdout,
|
||||||
stderr: os.Stderr,
|
stderr: os.Stderr,
|
||||||
|
|
Loading…
Reference in a new issue