mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 10:58:55 +00:00
return error if RESTIC_COMPRESSION env variable is invalid
This commit is contained in:
parent
f8910bc4ff
commit
01f0db4e56
@ -67,9 +67,10 @@ type CompressionMode uint
|
||||
|
||||
// Constants for the different compression levels.
|
||||
const (
|
||||
CompressionAuto CompressionMode = 0
|
||||
CompressionOff CompressionMode = 1
|
||||
CompressionMax CompressionMode = 2
|
||||
CompressionAuto CompressionMode = 0
|
||||
CompressionOff CompressionMode = 1
|
||||
CompressionMax CompressionMode = 2
|
||||
CompressionInvalid CompressionMode = 3
|
||||
)
|
||||
|
||||
// Set implements the method needed for pflag command flag parsing.
|
||||
@ -82,6 +83,7 @@ func (c *CompressionMode) Set(s string) error {
|
||||
case "max":
|
||||
*c = CompressionMax
|
||||
default:
|
||||
*c = CompressionInvalid
|
||||
return fmt.Errorf("invalid compression mode %q, must be one of (auto|off|max)", s)
|
||||
}
|
||||
|
||||
@ -107,6 +109,10 @@ func (c *CompressionMode) Type() string {
|
||||
|
||||
// New returns a new repository with backend be.
|
||||
func New(be restic.Backend, opts Options) (*Repository, error) {
|
||||
if opts.Compression == CompressionInvalid {
|
||||
return nil, errors.Fatalf("invalid compression mode")
|
||||
}
|
||||
|
||||
if opts.PackSize == 0 {
|
||||
opts.PackSize = DefaultPackSize
|
||||
}
|
||||
|
@ -679,3 +679,11 @@ func testStreamPack(t *testing.T, version uint) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestInvalidCompression(t *testing.T) {
|
||||
var comp repository.CompressionMode
|
||||
err := comp.Set("nope")
|
||||
rtest.Assert(t, err != nil, "missing error")
|
||||
_, err = repository.New(nil, repository.Options{Compression: comp})
|
||||
rtest.Assert(t, err != nil, "missing error")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user