github.com/artpar/rclone@v1.67.3/backend/union/policy/all.go (about)

     1  // Package policy provides utilities for the union implementation.
     2  package policy
     3  
     4  import (
     5  	"context"
     6  
     7  	"github.com/artpar/rclone/backend/union/upstream"
     8  	"github.com/artpar/rclone/fs"
     9  )
    10  
    11  func init() {
    12  	registerPolicy("all", &All{})
    13  }
    14  
    15  // All policy behaves the same as EpAll except for the CREATE category
    16  // Action category: same as epall.
    17  // Create category: apply to all branches.
    18  // Search category: same as epall.
    19  type All struct {
    20  	EpAll
    21  }
    22  
    23  // Create category policy, governing the creation of files and directories
    24  func (p *All) Create(ctx context.Context, upstreams []*upstream.Fs, path string) ([]*upstream.Fs, error) {
    25  	if len(upstreams) == 0 {
    26  		return nil, fs.ErrorObjectNotFound
    27  	}
    28  	upstreams = filterNC(upstreams)
    29  	if len(upstreams) == 0 {
    30  		return nil, fs.ErrorPermissionDenied
    31  	}
    32  	return upstreams, nil
    33  }
    34  
    35  // CreateEntries is CREATE category policy but receiving a set of candidate entries
    36  func (p *All) CreateEntries(entries ...upstream.Entry) ([]upstream.Entry, error) {
    37  	if len(entries) == 0 {
    38  		return nil, fs.ErrorObjectNotFound
    39  	}
    40  	entries = filterNCEntries(entries)
    41  	if len(entries) == 0 {
    42  		return nil, fs.ErrorPermissionDenied
    43  	}
    44  	return entries, nil
    45  }