corso/src/internal/kopia/data_collection.go
ashmrtn 226489c58f
use path struct in kopia DataCollection (#827)
* Use path struct in kopia DataCollection

Does not change the external API of the DataCollection any, just updates
internals in preparation for switching support of
data.Collection.FullPath.

* Expand Path interface slightly

kopia.Wrapper needs some extra functionality from paths, mostly along
the lines of directly manipulating the elements in the path. This gives
access to those functions.

* Use path struct in kopia.Wrapper for restore

Pass path structs to the newly created collections during restore.

* Add tests for new path functionality
2022-09-13 14:18:00 -07:00

53 lines
968 B
Go

package kopia
import (
"io"
"strings"
"github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/internal/path"
)
var (
_ data.Collection = &kopiaDataCollection{}
_ data.Stream = &kopiaDataStream{}
)
type kopiaDataCollection struct {
path path.Path
streams []data.Stream
}
func (kdc *kopiaDataCollection) Items() <-chan data.Stream {
res := make(chan data.Stream)
go func() {
defer close(res)
for _, s := range kdc.streams {
res <- s
}
}()
return res
}
func (kdc kopiaDataCollection) FullPath() []string {
// TODO(ashmrtn): Update this once data.Collection.FullPath supports
// path.Path. Assumes no adversarial users that use "/" in their folder names.
return strings.Split(kdc.path.String(), "/")
}
type kopiaDataStream struct {
reader io.ReadCloser
uuid string
}
func (kds kopiaDataStream) ToReader() io.ReadCloser {
return kds.reader
}
func (kds kopiaDataStream) UUID() string {
return kds.uuid
}