Make zfs.DatasetPath json.Marshaler and json.Unmarshaler
Had to resort to using pointers to zfs.DatasetPath everywhere... Should find a better solution for that.
This commit is contained in:
@@ -17,7 +17,7 @@ type DatasetMapFilter struct {
|
||||
}
|
||||
|
||||
type datasetMapFilterEntry struct {
|
||||
path zfs.DatasetPath
|
||||
path *zfs.DatasetPath
|
||||
// the mapping. since this datastructure acts as both mapping and filter
|
||||
// we have to convert it to the desired rep dynamically
|
||||
mapping string
|
||||
@@ -50,12 +50,10 @@ func (m *DatasetMapFilter) Add(pathPattern, mapping string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
var path zfs.DatasetPath
|
||||
pathStr := strings.TrimSuffix(pathPattern, SUBTREE_PATTERN)
|
||||
path, err = zfs.NewDatasetPath(pathStr)
|
||||
path, err := zfs.NewDatasetPath(pathStr)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("pattern is not a dataset path: %s", err)
|
||||
return
|
||||
return fmt.Errorf("pattern is not a dataset path: %s", err)
|
||||
}
|
||||
|
||||
entry := datasetMapFilterEntry{
|
||||
@@ -71,7 +69,7 @@ func (m *DatasetMapFilter) Add(pathPattern, mapping string) (err error) {
|
||||
// find the most specific prefix mapping we have
|
||||
//
|
||||
// longer prefix wins over shorter prefix, direct wins over glob
|
||||
func (m DatasetMapFilter) mostSpecificPrefixMapping(path zfs.DatasetPath) (idx int, found bool) {
|
||||
func (m DatasetMapFilter) mostSpecificPrefixMapping(path *zfs.DatasetPath) (idx int, found bool) {
|
||||
lcp, lcp_entry_idx := -1, -1
|
||||
direct_idx := -1
|
||||
for e := range m.entries {
|
||||
@@ -103,7 +101,7 @@ func (m DatasetMapFilter) mostSpecificPrefixMapping(path zfs.DatasetPath) (idx i
|
||||
return
|
||||
}
|
||||
|
||||
func (m DatasetMapFilter) Map(source zfs.DatasetPath) (target zfs.DatasetPath, err error) {
|
||||
func (m DatasetMapFilter) Map(source *zfs.DatasetPath) (target *zfs.DatasetPath, err error) {
|
||||
|
||||
if m.filterOnly {
|
||||
err = fmt.Errorf("using a filter for mapping simply does not work")
|
||||
@@ -136,7 +134,7 @@ func (m DatasetMapFilter) Map(source zfs.DatasetPath) (target zfs.DatasetPath, e
|
||||
return
|
||||
}
|
||||
|
||||
func (m DatasetMapFilter) Filter(p zfs.DatasetPath) (pass bool, err error) {
|
||||
func (m DatasetMapFilter) Filter(p *zfs.DatasetPath) (pass bool, err error) {
|
||||
mi, hasMapping := m.mostSpecificPrefixMapping(p)
|
||||
if !hasMapping {
|
||||
pass = false
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type DatasetMapping interface {
|
||||
Map(source zfs.DatasetPath) (target zfs.DatasetPath, err error)
|
||||
Map(source *zfs.DatasetPath) (target *zfs.DatasetPath, err error)
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
@@ -17,7 +17,7 @@ type Handler struct {
|
||||
SinkMappingFunc func(clientIdentity string) (mapping DatasetMapping, err error)
|
||||
}
|
||||
|
||||
func (h Handler) HandleFilesystemRequest(r rpc.FilesystemRequest) (roots []zfs.DatasetPath, err error) {
|
||||
func (h Handler) HandleFilesystemRequest(r rpc.FilesystemRequest) (roots []*zfs.DatasetPath, err error) {
|
||||
|
||||
h.Logger.Printf("handling fsr: %#v", r)
|
||||
|
||||
@@ -120,7 +120,7 @@ func (h Handler) HandlePullMeRequest(r rpc.PullMeRequest, clientIdentity string,
|
||||
return
|
||||
}
|
||||
|
||||
func (h Handler) pullACLCheck(p zfs.DatasetPath) (err error) {
|
||||
func (h Handler) pullACLCheck(p *zfs.DatasetPath) (err error) {
|
||||
var allowed bool
|
||||
allowed, err = h.PullACL.Filter(p)
|
||||
if err != nil {
|
||||
|
||||
+5
-5
@@ -143,7 +143,7 @@ func cmdRun(cmd *cobra.Command, args []string) {
|
||||
|
||||
type localPullACL struct{}
|
||||
|
||||
func (a localPullACL) Filter(p zfs.DatasetPath) (pass bool, err error) {
|
||||
func (a localPullACL) Filter(p *zfs.DatasetPath) (pass bool, err error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -250,15 +250,15 @@ func doPull(pull PullContext) (err error) {
|
||||
log := pull.Log
|
||||
|
||||
fsr := rpc.FilesystemRequest{}
|
||||
var remoteFilesystems []zfs.DatasetPath
|
||||
var remoteFilesystems []*zfs.DatasetPath
|
||||
if remoteFilesystems, err = remote.FilesystemRequest(fsr); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// build mapping (local->RemoteLocalMapping) + traversal datastructure
|
||||
type RemoteLocalMapping struct {
|
||||
Remote zfs.DatasetPath
|
||||
Local zfs.DatasetPath
|
||||
Remote *zfs.DatasetPath
|
||||
Local *zfs.DatasetPath
|
||||
}
|
||||
replMapping := make(map[string]RemoteLocalMapping, len(remoteFilesystems))
|
||||
localTraversal := zfs.NewDatasetPathForest()
|
||||
@@ -267,7 +267,7 @@ func doPull(pull PullContext) (err error) {
|
||||
log.Printf("mapping using %#v\n", pull.Mapping)
|
||||
for fs := range remoteFilesystems {
|
||||
var err error
|
||||
var localFs zfs.DatasetPath
|
||||
var localFs *zfs.DatasetPath
|
||||
localFs, err = pull.Mapping.Map(remoteFilesystems[fs])
|
||||
if err != nil {
|
||||
if err != NoMatchError {
|
||||
|
||||
Reference in New Issue
Block a user