mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 11:28:54 +00:00
Change repository type detection to first check if path is a directory that exists.
The method of determining if a repository exists doesn't work on Windows, since the "url.Scheme" will contain the drive letter - "c" in "c:\backup", so as a first step we check if the URL can be opened as a file, and if so, we assume it is a 'local' type repository.
This commit is contained in:
parent
fb3778abb6
commit
4dc746dac2
@ -132,7 +132,14 @@ func (o GlobalOptions) OpenRepository() (*repository.Repository, error) {
|
||||
// * s3://region/bucket -> amazon s3 bucket
|
||||
// * sftp://user@host/foo/bar -> remote sftp repository on host for user at path foo/bar
|
||||
// * sftp://host//tmp/backup -> remote sftp repository on host at path /tmp/backup
|
||||
// * c:\temp -> local repository at c:\temp - the path must exist
|
||||
func open(u string) (backend.Backend, error) {
|
||||
// check if the url is a directory that exists
|
||||
fi, err := os.Stat(u)
|
||||
if err == nil && fi.IsDir() {
|
||||
return local.Open(u)
|
||||
}
|
||||
|
||||
url, err := url.Parse(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -140,7 +147,13 @@ func open(u string) (backend.Backend, error) {
|
||||
|
||||
if url.Scheme == "" {
|
||||
return local.Open(url.Path)
|
||||
} else if url.Scheme == "s3" {
|
||||
}
|
||||
|
||||
if len(url.Path) < 1 {
|
||||
return nil, fmt.Errorf("unable to parse url %v", url)
|
||||
}
|
||||
|
||||
if url.Scheme == "s3" {
|
||||
return s3.Open(url.Host, url.Path[1:])
|
||||
}
|
||||
|
||||
@ -156,6 +169,12 @@ func open(u string) (backend.Backend, error) {
|
||||
|
||||
// Create the backend specified by URI.
|
||||
func create(u string) (backend.Backend, error) {
|
||||
// check if the url is a directory that exists
|
||||
fi, err := os.Stat(u)
|
||||
if err == nil && fi.IsDir() {
|
||||
return local.Create(u)
|
||||
}
|
||||
|
||||
url, err := url.Parse(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -163,7 +182,13 @@ func create(u string) (backend.Backend, error) {
|
||||
|
||||
if url.Scheme == "" {
|
||||
return local.Create(url.Path)
|
||||
} else if url.Scheme == "s3" {
|
||||
}
|
||||
|
||||
if len(url.Path) < 1 {
|
||||
return nil, fmt.Errorf("unable to parse url %v", url)
|
||||
}
|
||||
|
||||
if url.Scheme == "s3" {
|
||||
return s3.Open(url.Host, url.Path[1:])
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user