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:
Pauline Middelink 2017-03-08 20:12:16 +01:00
parent 3eaaa0f286
commit b4526c4e6e
7 changed files with 15 additions and 7 deletions

View file

@ -2,7 +2,6 @@ language: go
sudo: false
go:
- 1.6.4
- 1.7.5
- 1.8
- tip
@ -17,8 +16,6 @@ env:
matrix:
exclude:
- os: osx
go: 1.6.4
- os: osx
go: 1.7.5
- os: osx

View file

@ -77,7 +77,7 @@ Just clone the repository, `cd` to it and run `gb build` to build the binary:
[...]
$ bin/restic version
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:

View file

@ -34,7 +34,7 @@ You can download the latest pre-compiled binary from the [restic release page](h
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:
$ go run build.go

2
Vagrantfile vendored
View file

@ -1,7 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
GO_VERSION = '1.6'
GO_VERSION = '1.7'
def packages_freebsd
return <<-EOF

View file

@ -27,7 +27,7 @@ $ pacaur -S restic-git
# 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.
See the [Getting started](https://golang.org/doc/install) guide of the Go project for
instructions how to install Go.

View file

@ -1,6 +1,7 @@
package main
import (
"context"
"fmt"
"io"
"io/ioutil"
@ -33,6 +34,7 @@ type GlobalOptions struct {
NoLock bool
JSON bool
ctx context.Context
password string
stdout io.Writer
stderr io.Writer
@ -49,6 +51,13 @@ func init() {
globalOptions.password = pw
}
var cancel context.CancelFunc
globalOptions.ctx, cancel = context.WithCancel(context.Background())
AddCleanupHandler(func() error {
cancel()
return nil
})
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.PasswordFile, "password-file", "p", "", "read the repository password from a file")

View file

@ -1,6 +1,7 @@
package main
import (
"context"
"fmt"
"io/ioutil"
"os"
@ -194,6 +195,7 @@ func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions))
gopts := GlobalOptions{
Repo: env.repo,
Quiet: true,
ctx: context.Background(),
password: TestPassword,
stdout: os.Stdout,
stderr: os.Stderr,