change NewFileTree arg from url to path

main
bel 2023-11-05 09:33:28 -07:00
parent a2b66a03db
commit ceb28081d6
3 changed files with 9 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/url"
"path"
)
type (
@ -28,7 +29,11 @@ type (
func NewDriver(ctx context.Context, driver url.URL) (Driver, error) {
switch driver.Scheme {
case "filetree":
return NewFileTree(driver)
p := driver.Path
if driver.Host != "" {
p = path.Join(driver.Host, p)
}
return NewFileTree(p)
default:
return nil, fmt.Errorf("unknown driver spec %s", driver.String())
}

View File

@ -6,7 +6,6 @@ import (
"io"
"io/fs"
"io/ioutil"
"net/url"
"os"
"path"
"path/filepath"
@ -17,12 +16,8 @@ import (
type FileTree string
func NewFileTree(spec url.URL) (FileTree, error) {
p := spec.Path
if spec.Host != "" {
p = path.Join(spec.Host, p)
}
return FileTree(p), nil
func NewFileTree(root string) (FileTree, error) {
return FileTree(root), nil
}
func (tree FileTree) Keys(ctx context.Context) (chan Key, *error) {

View File

@ -1,17 +1,12 @@
package replicator
import (
"net/url"
"testing"
)
func TestFileTree(t *testing.T) {
d := t.TempDir()
u, err := url.Parse("filetree:///" + d)
if err != nil {
t.Fatal(err)
}
tree, err := NewFileTree(*u)
tree, err := NewFileTree(d)
if err != nil {
t.Fatal(err)
}