Documentation ¶
Index ¶
- Constants
- Variables
- func AddPermissions(l *provider.ResourcePermissions, r *provider.ResourcePermissions)
- func CalculateEtag(n *Node, tmTime time.Time) (string, error)
- func GetAvailableSize(path string) (uint64, error)
- func NoPermissions() provider.ResourcePermissions
- func OwnerPermissions() provider.ResourcePermissions
- func ShareFolderPermissions() provider.ResourcePermissions
- type Attributes
- func (md Attributes) Int64(key string) (int64, error)
- func (md Attributes) SetInt64(key string, val int64)
- func (md Attributes) SetString(key, val string)
- func (md Attributes) SetUInt64(key string, val uint64)
- func (md Attributes) String(key string) string
- func (md Attributes) UInt64(key string) (uint64, error)
- type Node
- func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissions, ...) (ri *provider.ResourceInfo, err error)
- func (n *Node) CheckLock(ctx context.Context) error
- func (n *Node) Child(ctx context.Context, name string) (*Node, error)
- func (n *Node) DeleteGrant(ctx context.Context, g *provider.Grant, acquireLock bool) (err error)
- func (n *Node) FindStorageSpaceRoot(ctx context.Context) error
- func (n *Node) GetBlobSize(ctx context.Context) (treesize uint64, err error)
- func (n *Node) GetDTime(ctx context.Context) (tmTime time.Time, err error)
- func (n *Node) GetMTime(ctx context.Context) (time.Time, error)
- func (n *Node) GetTMTime(ctx context.Context) (time.Time, error)
- func (n *Node) GetTreeSize(ctx context.Context) (treesize uint64, err error)
- func (n *Node) HasPropagation(ctx context.Context) (propagation bool)
- func (n *Node) InternalPath() string
- func (n *Node) IsDenied(ctx context.Context) bool
- func (n *Node) IsDir(ctx context.Context) bool
- func (n *Node) IsDisabled(ctx context.Context) bool
- func (n *Node) IsProcessing(ctx context.Context) bool
- func (n *Node) IsSpaceRoot(ctx context.Context) bool
- func (n *Node) ListGrantees(ctx context.Context) (grantees []string, err error)
- func (n *Node) ListGrants(ctx context.Context) ([]*provider.Grant, error)
- func (n *Node) LockFilePath() string
- func (n *Node) NodeMetadata(ctx context.Context) Attributes
- func (n *Node) Owner() *userpb.UserId
- func (n *Node) Parent(ctx context.Context) (p *Node, err error)
- func (n *Node) ParentPath() string
- func (n *Node) ParentWithReader(ctx context.Context, r io.Reader) (*Node, error)
- func (n *Node) PermissionSet(ctx context.Context) (provider.ResourcePermissions, bool)
- func (n *Node) ReadGrant(ctx context.Context, grantee string) (g *provider.Grant, err error)
- func (n Node) ReadLock(ctx context.Context, skipFileLock bool) (*provider.Lock, error)
- func (n *Node) ReadUserPermissions(ctx context.Context, u *userpb.User) (ap provider.ResourcePermissions, accessDenied bool, err error)
- func (n *Node) RefreshLock(ctx context.Context, lock *provider.Lock, existingLockID string) error
- func (n *Node) RemoveXattr(ctx context.Context, key string, acquireLock bool) error
- func (n *Node) ScanData(ctx context.Context) (scanned bool, virus string, scantime time.Time)
- func (n *Node) SetChecksum(ctx context.Context, csType string, h hash.Hash) (err error)
- func (n *Node) SetDTime(ctx context.Context, t *time.Time) (err error)
- func (n *Node) SetEtag(ctx context.Context, val string) (err error)
- func (n *Node) SetFavorite(ctx context.Context, uid *userpb.UserId, val string) error
- func (n *Node) SetLock(ctx context.Context, lock *provider.Lock) error
- func (n *Node) SetMtime(ctx context.Context, t *time.Time) (err error)
- func (n *Node) SetMtimeString(ctx context.Context, mtime string) error
- func (n *Node) SetOwner(owner *userpb.UserId)
- func (n *Node) SetScanData(ctx context.Context, info string, date time.Time) error
- func (n *Node) SetTMTime(ctx context.Context, t *time.Time) (err error)
- func (n *Node) SetTreeSize(ctx context.Context, ts uint64) (err error)
- func (n *Node) SetType(t provider.ResourceType)
- func (n *Node) SetXattr(ctx context.Context, key string, val []byte) (err error)
- func (n *Node) SetXattrString(ctx context.Context, key, val string) (err error)
- func (n *Node) SetXattrs(attribs map[string][]byte, acquireLock bool) (err error)
- func (n *Node) SetXattrsWithContext(ctx context.Context, attribs map[string][]byte, acquireLock bool) (err error)
- func (n *Node) SpaceOwnerOrManager(ctx context.Context) *userpb.UserId
- func (n *Node) Type(ctx context.Context) provider.ResourceType
- func (n *Node) Unlock(ctx context.Context, lock *provider.Lock) error
- func (n *Node) UnmarkProcessing(ctx context.Context, uploadID string) error
- func (n *Node) UnsetTempEtag(ctx context.Context) (err error)
- func (n *Node) Xattr(ctx context.Context, key string) ([]byte, error)
- func (n *Node) XattrInt32(ctx context.Context, key string) (int32, error)
- func (n *Node) XattrInt64(ctx context.Context, key string) (int64, error)
- func (n *Node) XattrString(ctx context.Context, key string) (string, error)
- func (n *Node) XattrUint64(ctx context.Context, key string) (uint64, error)
- func (n *Node) Xattrs(ctx context.Context) (Attributes, error)
- func (n *Node) XattrsWithReader(ctx context.Context, r io.Reader) (Attributes, error)
- type PathLookup
- type PermissionFunc
- type Permissions
Constants ¶
const ( LockdiscoveryKey = "lockdiscovery" FavoriteKey = "http://owncloud.org/ns/favorite" ChecksumsKey = "http://owncloud.org/ns/checksums" QuotaKey = "quota" QuotaUnlimited = "0" QuotaUncalculated = "-1" QuotaUnknown = "-2" // TrashIDDelimiter represents the characters used to separate the nodeid and the deletion time. TrashIDDelimiter = ".T." RevisionIDDelimiter = ".REV." // RootID defines the root node's ID RootID = "root" // ProcessingStatus is the name of the status when processing a file ProcessingStatus = "processing:" )
Define keys and values used in the node metadata
Variables ¶
var CheckQuota = func(ctx context.Context, spaceRoot *Node, overwrite bool, oldSize, newSize uint64) (quotaSufficient bool, err error) { used, _ := spaceRoot.GetTreeSize(ctx) if !enoughDiskSpace(spaceRoot.InternalPath(), newSize) { return false, errtypes.InsufficientStorage("disk full") } quotaByteStr, _ := spaceRoot.XattrString(ctx, prefixes.QuotaAttr) switch quotaByteStr { case "": return true, nil case QuotaUnlimited: return true, nil case QuotaUncalculated: return true, nil case QuotaUnknown: return true, nil } quotaByte, _ := strconv.ParseUint(quotaByteStr, 10, 64) if overwrite { if quotaByte < used-oldSize+newSize { return false, errtypes.InsufficientStorage("quota exceeded") } } else if newSize > quotaByte-used || quotaByte < used { return false, errtypes.InsufficientStorage("quota exceeded") } return true, nil }
CheckQuota checks if both disk space and available quota are sufficient Overwrite must be set to true if the new file replaces the old file e.g. when creating a new file version. In such a case the function will reduce the used bytes by the old file size and then add the new size. If overwrite is false oldSize will be ignored.
Functions ¶
func AddPermissions ¶
func AddPermissions(l *provider.ResourcePermissions, r *provider.ResourcePermissions)
AddPermissions merges a set of permissions into another TODO we should use a bitfield for this ...
func CalculateEtag ¶
CalculateEtag returns a hash of fileid + tmtime (or mtime)
func GetAvailableSize ¶
GetAvailableSize stats the filesystem and return the available bytes
func NoPermissions ¶
func NoPermissions() provider.ResourcePermissions
NoPermissions represents an empty set of permissions
func OwnerPermissions ¶
func OwnerPermissions() provider.ResourcePermissions
OwnerPermissions defines permissions for nodes owned by the user
func ShareFolderPermissions ¶
func ShareFolderPermissions() provider.ResourcePermissions
ShareFolderPermissions defines permissions for the shared jail
Types ¶
type Attributes ¶ added in v2.13.0
Attributes is a map of string keys and byte array values
func (Attributes) Int64 ¶ added in v2.13.0
func (md Attributes) Int64(key string) (int64, error)
Int64 reads an int64 value
func (Attributes) SetInt64 ¶ added in v2.13.0
func (md Attributes) SetInt64(key string, val int64)
SetInt64 sets an int64 value
func (Attributes) SetString ¶ added in v2.13.0
func (md Attributes) SetString(key, val string)
SetString sets a string value
func (Attributes) SetUInt64 ¶ added in v2.16.0
func (md Attributes) SetUInt64(key string, val uint64)
SetInt64 sets an uint64 value
func (Attributes) String ¶ added in v2.13.0
func (md Attributes) String(key string) string
String reads a String value
type Node ¶
type Node struct { SpaceID string ParentID string ID string Name string Blobsize int64 BlobID string Exists bool SpaceRoot *Node // contains filtered or unexported fields }
Node represents a node in the tree and provides methods to get a Parent or Child instance
func New ¶
func New(spaceID, id, parentID, name string, blobsize int64, blobID string, t provider.ResourceType, owner *userpb.UserId, lu PathLookup) *Node
New returns a new instance of Node
func ReadNode ¶
func ReadNode(ctx context.Context, lu PathLookup, spaceID, nodeID string, canListDisabledSpace bool, spaceRoot *Node, skipParentCheck bool) (*Node, error)
ReadNode creates a new instance from an id and checks if it exists
func (*Node) AsResourceInfo ¶
func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissions, mdKeys, fieldMask []string, returnBasename bool) (ri *provider.ResourceInfo, err error)
AsResourceInfo return the node as CS3 ResourceInfo
func (*Node) DeleteGrant ¶ added in v2.16.0
ReadGrant reads a CS3 grant
func (*Node) FindStorageSpaceRoot ¶
FindStorageSpaceRoot calls n.Parent() and climbs the tree until it finds the space root node and adds it to the node
func (*Node) GetBlobSize ¶ added in v2.12.0
GetBlobSize reads the blobsize from the extended attributes
func (*Node) GetMTime ¶ added in v2.13.0
GetMTime reads the mtime from the extended attributes, falling back to disk
func (*Node) GetTMTime ¶
GetTMTime reads the tmtime from the extended attributes, falling back to GetMTime()
func (*Node) GetTreeSize ¶
GetTreeSize reads the treesize from the extended attributes
func (*Node) HasPropagation ¶
HasPropagation checks if the propagation attribute exists and is set to "1"
func (*Node) InternalPath ¶
InternalPath returns the internal path of the Node
func (*Node) IsDisabled ¶
IsDisabled returns true when the node has a dmtime attribute set only used to check if a space is disabled FIXME confusing with the trash logic
func (*Node) IsProcessing ¶ added in v2.13.0
IsProcessing returns true if the node is currently being processed
func (*Node) IsSpaceRoot ¶ added in v2.12.0
IsSpaceRoot checks if the node is a space root
func (*Node) ListGrantees ¶
ListGrantees lists the grantees of the current node We don't want to wast time and memory by creating grantee objects. The function will return a list of opaque strings that can be used to make a ReadGrant call
func (*Node) ListGrants ¶
ListGrants lists all grants of the current node.
func (*Node) LockFilePath ¶
LockFilePath returns the internal path of the lock file of the node
func (*Node) NodeMetadata ¶ added in v2.13.0
func (n *Node) NodeMetadata(ctx context.Context) Attributes
NodeMetadata writes the Node metadata to disk and allows passing additional attributes
func (*Node) ParentPath ¶ added in v2.13.0
ParentPath returns the internal path of the parent of the current node
func (*Node) ParentWithReader ¶ added in v2.13.3
ParentWithReader returns the parent node
func (*Node) PermissionSet ¶
PermissionSet returns the permission set and an accessDenied flag for the current user the parent nodes are not taken into account accessDenied is separate from the resource permissions because we only support full denials
func (*Node) ReadUserPermissions ¶
func (n *Node) ReadUserPermissions(ctx context.Context, u *userpb.User) (ap provider.ResourcePermissions, accessDenied bool, err error)
ReadUserPermissions will assemble the permissions for the current user on the given node without parent nodes we indicate if the access was denied by setting a grant with no permissions
func (*Node) RefreshLock ¶
RefreshLock refreshes the node's lock
func (*Node) RemoveXattr ¶ added in v2.12.0
RemoveXattr removes an extended attribute from the write-through cache/node
func (*Node) SetChecksum ¶
SetChecksum writes the checksum with the given checksum type to the extended attributes
func (*Node) SetDTime ¶
SetDTime writes the UTC dtime to the extended attributes or removes the attribute if nil is passed
func (*Node) SetEtag ¶
SetEtag sets the temporary etag of a node if it differs from the current etag
func (*Node) SetFavorite ¶
SetFavorite sets the favorite for the current user TODO we should not mess with the user here ... the favorites is now a user specific property for a file that cannot be mapped to extended attributes without leaking who has marked a file as a favorite it is a specific case of a tag, which is user individual as well TODO there are different types of tags 1. public that are managed by everyone 2. private tags that are only visible to the user 3. system tags that are only visible to the system 4. group tags that are only visible to a group ... urgh ... well this can be solved using different namespaces 1. public = p: 2. private = u:<uid>: for user specific 3. system = s: for system 4. group = g:<gid>: 5. app? = a:<aid>: for apps? obviously this only is secure when the u/s/g/a namespaces are not accessible by users in the filesystem public tags can be mapped to extended attributes
func (*Node) SetMtime ¶
SetMTime writes the UTC mtime to the extended attributes or removes the attribute if nil is passed
func (*Node) SetMtimeString ¶ added in v2.12.0
SetMtimeString sets the mtime and atime of a node to the unixtime parsed from the given string
func (*Node) SetScanData ¶ added in v2.13.0
SetScanData sets the virus scan info to the node
func (*Node) SetTMTime ¶
SetTMTime writes the UTC tmtime to the extended attributes or removes the attribute if nil is passed
func (*Node) SetTreeSize ¶
SetTreeSize writes the treesize to the extended attributes
func (*Node) SetType ¶ added in v2.13.0
func (n *Node) SetType(t provider.ResourceType)
SetType sets the type of the node.
func (*Node) SetXattr ¶ added in v2.12.0
SetXattr sets an extended attribute on the write-through cache/node
func (*Node) SetXattrString ¶ added in v2.13.0
SetXattrString sets a string extended attribute on the write-through cache/node
func (*Node) SetXattrs ¶ added in v2.12.0
SetXattrs sets multiple extended attributes on the write-through cache/node
func (*Node) SetXattrsWithContext ¶ added in v2.15.0
func (n *Node) SetXattrsWithContext(ctx context.Context, attribs map[string][]byte, acquireLock bool) (err error)
SetXattrs sets multiple extended attributes on the write-through cache/node
func (*Node) SpaceOwnerOrManager ¶ added in v2.11.0
SpaceOwnerOrManager returns the space owner of the space. If no owner is set one of the space managers is returned instead.
func (*Node) Type ¶ added in v2.13.0
func (n *Node) Type(ctx context.Context) provider.ResourceType
Type returns the node's resource type
func (*Node) UnmarkProcessing ¶ added in v2.13.0
UnmarkProcessing removes the processing flag from the node
func (*Node) UnsetTempEtag ¶
UnsetTempEtag removes the temporary etag attribute
func (*Node) Xattr ¶ added in v2.12.0
Xattr returns an extended attribute of the node. If the attributes have already been cached it is not read from disk again.
func (*Node) XattrInt32 ¶ added in v2.13.0
XattrInt32 returns the int32 representation of an attribute
func (*Node) XattrInt64 ¶ added in v2.13.0
XattrInt64 returns the int64 representation of an attribute
func (*Node) XattrString ¶ added in v2.13.0
XattrString returns the string representation of an attribute
func (*Node) XattrUint64 ¶ added in v2.15.0
XattrUint64 returns the uint64 representation of an attribute
func (*Node) Xattrs ¶ added in v2.12.0
func (n *Node) Xattrs(ctx context.Context) (Attributes, error)
Xattrs returns the extended attributes of the node. If the attributes have already been cached they are not read from disk again.
func (*Node) XattrsWithReader ¶ added in v2.13.3
XattrsWithReader returns the extended attributes of the node. If the attributes have already been cached they are not read from disk again.
type PathLookup ¶
type PathLookup interface { InternalRoot() string InternalPath(spaceID, nodeID string) string Path(ctx context.Context, n *Node, hasPermission PermissionFunc) (path string, err error) MetadataBackend() metadata.Backend ReadBlobSizeAttr(ctx context.Context, path string) (int64, error) ReadBlobIDAttr(ctx context.Context, path string) (string, error) }
PathLookup defines the interface for the lookup component
type PermissionFunc ¶ added in v2.13.0
PermissionFunc should return true when the user has permission to access the node
var ( // NoCheck doesn't check permissions, returns true always NoCheck PermissionFunc = func(_ *Node) bool { return true } )
type Permissions ¶
type Permissions struct {
// contains filtered or unexported fields
}
Permissions implements permission checks
func NewPermissions ¶
func NewPermissions(lu PathLookup) *Permissions
NewPermissions returns a new Permissions instance
func (*Permissions) AssemblePermissions ¶
func (p *Permissions) AssemblePermissions(ctx context.Context, n *Node) (ap provider.ResourcePermissions, err error)
AssemblePermissions will assemble the permissions for the current user on the given node, taking into account all parent nodes
func (*Permissions) AssembleTrashPermissions ¶ added in v2.15.0
func (p *Permissions) AssembleTrashPermissions(ctx context.Context, n *Node) (ap provider.ResourcePermissions, err error)
AssembleTrashPermissions will assemble the permissions for the current user on the given node, taking into account all parent nodes