github.com/pachyderm/pachyderm@v1.13.4/src/server/pfs/fuse/options.go (about)

     1  package fuse
     2  
     3  import (
     4  	"github.com/hanwen/go-fuse/v2/fs"
     5  
     6  	"github.com/pachyderm/pachyderm/src/client"
     7  	"github.com/pachyderm/pachyderm/src/client/pkg/errors"
     8  	"github.com/pachyderm/pachyderm/src/server/pkg/errutil"
     9  	"github.com/pachyderm/pachyderm/src/server/pkg/uuid"
    10  )
    11  
    12  // Options is for configuring fuse mounts. Any of the fields may be left nil
    13  // and `nil` itself is a valid set of Options which uses the default for
    14  // everything.
    15  type Options struct {
    16  	Fuse *fs.Options
    17  
    18  	// Write indicates that the pfs mount should allow writes.
    19  	// Writes will be written back to the filesystem.
    20  	Write bool
    21  
    22  	// RepoOptions is a map from repo names to options associated with them.
    23  	RepoOptions map[string]*RepoOptions
    24  
    25  	// Unmount is a channel that will be closed when the filesystem has been
    26  	// unmounted. It can be nil in which case it's ignored.
    27  	Unmount chan struct{}
    28  }
    29  
    30  // RepoOptions are the options associated with a mounted repo.
    31  type RepoOptions struct {
    32  	// Branch is the branch of the repo to mount
    33  	Branch string
    34  	// Write indicates that the repo should be mounted for writing.
    35  	Write bool
    36  }
    37  
    38  func (o *Options) getFuse() *fs.Options {
    39  	if o == nil || o.Fuse == nil {
    40  		// We always return a struct here because otherwise the defaults that
    41  		// fuse sets make files inaccessible.
    42  		return &fs.Options{}
    43  	}
    44  	return o.Fuse
    45  }
    46  
    47  func (o *Options) getRepoOpts() map[string]*RepoOptions {
    48  	if o == nil {
    49  		return make(map[string]*RepoOptions)
    50  	}
    51  	return o.RepoOptions
    52  }
    53  
    54  func (o *Options) getBranches() map[string]string {
    55  	result := make(map[string]string)
    56  	if o == nil {
    57  		return result
    58  	}
    59  	for repo, opts := range o.RepoOptions {
    60  		if opts.Branch != "" {
    61  			result[repo] = opts.Branch
    62  		}
    63  	}
    64  	return result
    65  }
    66  
    67  func (o *Options) getWrite() bool {
    68  	if o == nil {
    69  		return false
    70  	}
    71  	return o.Write
    72  }
    73  
    74  func (o *Options) getUnmount() chan struct{} {
    75  	if o == nil {
    76  		return nil
    77  	}
    78  	return o.Unmount
    79  }
    80  
    81  func (o *Options) validate(c *client.APIClient) error {
    82  	if o == nil {
    83  		return nil
    84  	}
    85  	for repo, opts := range o.RepoOptions {
    86  		if opts.Write {
    87  			if uuid.IsUUIDWithoutDashes(opts.Branch) {
    88  				return errors.Errorf("can't mount commit %s@%s in Write mode (mount a branch instead)", repo, opts.Branch)
    89  			}
    90  			bi, err := c.InspectBranch(repo, opts.Branch)
    91  			if err != nil && !errutil.IsNotFoundError(err) {
    92  				return err
    93  			}
    94  			if bi != nil && len(bi.Provenance) > 0 {
    95  				return errors.Errorf("can't mount branch %s@%s in Write mode because it's an output branch", repo, opts.Branch)
    96  			}
    97  		}
    98  	}
    99  	return nil
   100  }