github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/backend/union/policy/all.go (about)

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