mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
parent
d097d40237
commit
ed09887d9e
@ -2,6 +2,7 @@ package sftp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
@ -31,7 +32,12 @@ func ParseConfig(s string) (interface{}, error) {
|
||||
user = url.User.Username()
|
||||
}
|
||||
host = url.Host
|
||||
dir = url.Path[1:]
|
||||
dir = url.Path
|
||||
if dir == "" {
|
||||
return nil, fmt.Errorf("invalid backend %q, no directory specified", s)
|
||||
}
|
||||
|
||||
dir = dir[1:]
|
||||
case strings.HasPrefix(s, "sftp:"):
|
||||
// parse the sftp:user@host:path format, which means we'll get
|
||||
// "user@host:path" in s
|
||||
|
@ -74,3 +74,17 @@ func TestParseConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var configTestsInvalid = []string{
|
||||
"sftp://host:dir",
|
||||
}
|
||||
|
||||
func TestParseConfigInvalid(t *testing.T) {
|
||||
for i, test := range configTestsInvalid {
|
||||
_, err := ParseConfig(test)
|
||||
if err == nil {
|
||||
t.Errorf("test %d: invalid config %s did not return an error", i, test)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user