2022-08-28 13:21:57 +02:00
|
|
|
// Package policy provides utilities for the union implementation.
|
2019-11-30 15:41:39 +01:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/rclone/rclone/backend/union/upstream"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
registerPolicy("all", &All{})
|
|
|
|
}
|
|
|
|
|
|
|
|
// All policy behaves the same as EpAll except for the CREATE category
|
|
|
|
// Action category: same as epall.
|
|
|
|
// Create category: apply to all branches.
|
|
|
|
// Search category: same as epall.
|
|
|
|
type All struct {
|
|
|
|
EpAll
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create category policy, governing the creation of files and directories
|
|
|
|
func (p *All) Create(ctx context.Context, upstreams []*upstream.Fs, path string) ([]*upstream.Fs, error) {
|
|
|
|
if len(upstreams) == 0 {
|
|
|
|
return nil, fs.ErrorObjectNotFound
|
|
|
|
}
|
|
|
|
upstreams = filterNC(upstreams)
|
|
|
|
if len(upstreams) == 0 {
|
|
|
|
return nil, fs.ErrorPermissionDenied
|
|
|
|
}
|
|
|
|
return upstreams, nil
|
|
|
|
}
|
|
|
|
|
2020-05-20 12:39:20 +02:00
|
|
|
// CreateEntries is CREATE category policy but receiving a set of candidate entries
|
2019-11-30 15:41:39 +01:00
|
|
|
func (p *All) CreateEntries(entries ...upstream.Entry) ([]upstream.Entry, error) {
|
|
|
|
if len(entries) == 0 {
|
|
|
|
return nil, fs.ErrorObjectNotFound
|
|
|
|
}
|
|
|
|
entries = filterNCEntries(entries)
|
|
|
|
if len(entries) == 0 {
|
|
|
|
return nil, fs.ErrorPermissionDenied
|
|
|
|
}
|
|
|
|
return entries, nil
|
|
|
|
}
|