change NewFileTree arg from url to path
parent
a2b66a03db
commit
ceb28081d6
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
@ -28,7 +29,11 @@ type (
|
||||||
func NewDriver(ctx context.Context, driver url.URL) (Driver, error) {
|
func NewDriver(ctx context.Context, driver url.URL) (Driver, error) {
|
||||||
switch driver.Scheme {
|
switch driver.Scheme {
|
||||||
case "filetree":
|
case "filetree":
|
||||||
return NewFileTree(driver)
|
p := driver.Path
|
||||||
|
if driver.Host != "" {
|
||||||
|
p = path.Join(driver.Host, p)
|
||||||
|
}
|
||||||
|
return NewFileTree(p)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown driver spec %s", driver.String())
|
return nil, fmt.Errorf("unknown driver spec %s", driver.String())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -17,12 +16,8 @@ import (
|
||||||
|
|
||||||
type FileTree string
|
type FileTree string
|
||||||
|
|
||||||
func NewFileTree(spec url.URL) (FileTree, error) {
|
func NewFileTree(root string) (FileTree, error) {
|
||||||
p := spec.Path
|
return FileTree(root), nil
|
||||||
if spec.Host != "" {
|
|
||||||
p = path.Join(spec.Host, p)
|
|
||||||
}
|
|
||||||
return FileTree(p), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tree FileTree) Keys(ctx context.Context) (chan Key, *error) {
|
func (tree FileTree) Keys(ctx context.Context) (chan Key, *error) {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,12 @@
|
||||||
package replicator
|
package replicator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFileTree(t *testing.T) {
|
func TestFileTree(t *testing.T) {
|
||||||
d := t.TempDir()
|
d := t.TempDir()
|
||||||
u, err := url.Parse("filetree:///" + d)
|
tree, err := NewFileTree(d)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
tree, err := NewFileTree(*u)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue