mirror of
https://github.com/rclone/rclone.git
synced 2025-01-06 22:40:24 +01:00
lib/bucket: implement bucket.Join a simplified path.Join
This commit is contained in:
parent
e00bf3d723
commit
66c8d3bf2b
@ -29,6 +29,23 @@ func Split(absPath string) (bucket, bucketPath string) {
|
|||||||
return absPath[:slash], absPath[slash+1:]
|
return absPath[:slash], absPath[slash+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Join joins any number of path elements into a single path, adding a
|
||||||
|
// separating slash if necessary. Empty elements are ignored.
|
||||||
|
//
|
||||||
|
// Unlike path.Join this does not run path.Clean on the elements so a
|
||||||
|
// path called "." will be preserved.
|
||||||
|
func Join(elem ...string) (out string) {
|
||||||
|
for _, e := range elem {
|
||||||
|
if e != "" {
|
||||||
|
if out != "" {
|
||||||
|
out += "/"
|
||||||
|
}
|
||||||
|
out += e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// Cache stores whether buckets are available and their IDs
|
// Cache stores whether buckets are available and their IDs
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
mu sync.Mutex // mutex to protect created and deleted
|
mu sync.Mutex // mutex to protect created and deleted
|
||||||
|
@ -2,6 +2,7 @@ package bucket
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -24,6 +25,25 @@ func TestSplit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJoin(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
in []string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{in: []string{}, want: ""},
|
||||||
|
{in: []string{""}, want: ""},
|
||||||
|
{in: []string{"", ""}, want: ""},
|
||||||
|
{in: []string{"", "b"}, want: "b"},
|
||||||
|
{in: []string{"a", ""}, want: "a"},
|
||||||
|
{in: []string{"a", "b"}, want: "a/b"},
|
||||||
|
{in: []string{"a/b/c", "..", "."}, want: "a/b/c/../."},
|
||||||
|
} {
|
||||||
|
got := Join(test.in...)
|
||||||
|
what := fmt.Sprintf("Join(%q)", test.in)
|
||||||
|
assert.Equal(t, test.want, got, what)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCache(t *testing.T) {
|
func TestCache(t *testing.T) {
|
||||||
c := NewCache()
|
c := NewCache()
|
||||||
errBoom := errors.New("boom")
|
errBoom := errors.New("boom")
|
||||||
|
Loading…
Reference in New Issue
Block a user