github.com/cs3org/reva/v2@v2.27.7/pkg/storage/utils/decomposedfs/metadata/metadata.go (about)

     1  // Copyright 2018-2021 CERN
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package metadata
    20  
    21  import (
    22  	"context"
    23  	"errors"
    24  	"io"
    25  
    26  	"go.opentelemetry.io/otel"
    27  	"go.opentelemetry.io/otel/trace"
    28  )
    29  
    30  var tracer trace.Tracer
    31  
    32  func init() {
    33  	tracer = otel.Tracer("github.com/cs3org/reva/pkg/storage/utils/decomposedfs/metadata")
    34  }
    35  
    36  var errUnconfiguredError = errors.New("no metadata backend configured. Bailing out")
    37  
    38  type UnlockFunc func() error
    39  
    40  // Backend defines the interface for file attribute backends
    41  type Backend interface {
    42  	Name() string
    43  
    44  	All(ctx context.Context, path string) (map[string][]byte, error)
    45  	Get(ctx context.Context, path, key string) ([]byte, error)
    46  
    47  	GetInt64(ctx context.Context, path, key string) (int64, error)
    48  	List(ctx context.Context, path string) (attribs []string, err error)
    49  	Set(ctx context.Context, path, key string, val []byte) error
    50  	SetMultiple(ctx context.Context, path string, attribs map[string][]byte, acquireLock bool) error
    51  	Remove(ctx context.Context, path, key string, acquireLock bool) error
    52  
    53  	Lock(path string) (UnlockFunc, error)
    54  	Purge(ctx context.Context, path string) error
    55  	Rename(oldPath, newPath string) error
    56  	IsMetaFile(path string) bool
    57  	MetadataPath(path string) string
    58  	LockfilePath(path string) string
    59  
    60  	AllWithLockedSource(ctx context.Context, path string, source io.Reader) (map[string][]byte, error)
    61  }
    62  
    63  // NullBackend is the default stub backend, used to enforce the configuration of a proper backend
    64  type NullBackend struct{}
    65  
    66  // Name returns the name of the backend
    67  func (NullBackend) Name() string { return "null" }
    68  
    69  // All reads all extended attributes for a node
    70  func (NullBackend) All(ctx context.Context, path string) (map[string][]byte, error) {
    71  	return nil, errUnconfiguredError
    72  }
    73  
    74  // Get an extended attribute value for the given key
    75  func (NullBackend) Get(ctx context.Context, path, key string) ([]byte, error) {
    76  	return []byte{}, errUnconfiguredError
    77  }
    78  
    79  // GetInt64 reads a string as int64 from the xattrs
    80  func (NullBackend) GetInt64(ctx context.Context, path, key string) (int64, error) {
    81  	return 0, errUnconfiguredError
    82  }
    83  
    84  // List retrieves a list of names of extended attributes associated with the
    85  // given path in the file system.
    86  func (NullBackend) List(ctx context.Context, path string) ([]string, error) {
    87  	return nil, errUnconfiguredError
    88  }
    89  
    90  // Set sets one attribute for the given path
    91  func (NullBackend) Set(ctx context.Context, path string, key string, val []byte) error {
    92  	return errUnconfiguredError
    93  }
    94  
    95  // SetMultiple sets a set of attribute for the given path
    96  func (NullBackend) SetMultiple(ctx context.Context, path string, attribs map[string][]byte, acquireLock bool) error {
    97  	return errUnconfiguredError
    98  }
    99  
   100  // Remove removes an extended attribute key
   101  func (NullBackend) Remove(ctx context.Context, path string, key string, acquireLock bool) error {
   102  	return errUnconfiguredError
   103  }
   104  
   105  // Lock locks the metadata for the given path
   106  func (NullBackend) Lock(path string) (UnlockFunc, error) {
   107  	return nil, nil
   108  }
   109  
   110  // IsMetaFile returns whether the given path represents a meta file
   111  func (NullBackend) IsMetaFile(path string) bool { return false }
   112  
   113  // Purge purges the data of a given path from any cache that might hold it
   114  func (NullBackend) Purge(_ context.Context, purges string) error { return errUnconfiguredError }
   115  
   116  // Rename moves the data for a given path to a new path
   117  func (NullBackend) Rename(oldPath, newPath string) error { return errUnconfiguredError }
   118  
   119  // MetadataPath returns the path of the file holding the metadata for the given path
   120  func (NullBackend) MetadataPath(path string) string { return "" }
   121  
   122  // LockfilePath returns the path of the lock file
   123  func (NullBackend) LockfilePath(path string) string { return "" }
   124  
   125  // AllWithLockedSource reads all extended attributes from the given reader
   126  // The path argument is used for storing the data in the cache
   127  func (NullBackend) AllWithLockedSource(ctx context.Context, path string, source io.Reader) (map[string][]byte, error) {
   128  	return nil, errUnconfiguredError
   129  }