node

package
v2.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2022 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockdiscoveryKey = "DAV:lockdiscovery"
	FavoriteKey      = "http://owncloud.org/ns/favorite"
	ShareTypesKey    = "http://owncloud.org/ns/share-types"
	ChecksumsKey     = "http://owncloud.org/ns/checksums"
	UserShareType    = "0"
	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"
)

Define keys and values used in the node metadata

Variables

View Source
var CheckQuota = func(spaceRoot *Node, overwrite bool, oldSize, newSize uint64) (quotaSufficient bool, err error) {
	used, _ := spaceRoot.GetTreeSize()
	if !enoughDiskSpace(spaceRoot.InternalPath(), newSize) {
		return false, errtypes.InsufficientStorage("disk full")
	}
	quotaByteStr, _ := xattrs.Get(spaceRoot.InternalPath(), xattrs.QuotaAttr)
	if quotaByteStr == "" || quotaByteStr == QuotaUnlimited {

		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

AddPermissions merges a set of permissions into another TODO we should use a bitfield for this ...

func CalculateEtag

func CalculateEtag(nodeID string, tmTime time.Time) (string, error)

CalculateEtag returns a hash of fileid + tmtime (or mtime)

func GetAvailableSize

func GetAvailableSize(path string) (uint64, error)

GetAvailableSize stats the filesystem and return the available bytes

func IsSpaceRoot

func IsSpaceRoot(r *Node) bool

IsSpaceRoot checks if the node is a space root

func NoOwnerPermissions

func NoOwnerPermissions() provider.ResourcePermissions

NoOwnerPermissions defines permissions for nodes that don't have an owner set, eg the root node

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 ReadBlobIDAttr added in v2.4.0

func ReadBlobIDAttr(path string) (string, error)

ReadBlobIDAttr reads the blobsize from the xattrs

func ReadBlobSizeAttr

func ReadBlobSizeAttr(path string) (int64, error)

ReadBlobSizeAttr reads the blobsize from the xattrs

func ShareFolderPermissions

func ShareFolderPermissions() provider.ResourcePermissions

ShareFolderPermissions defines permissions for the shared jail

Types

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, 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) (n *Node, err 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) ChangeOwner

func (n *Node) ChangeOwner(new *userpb.UserId) (err error)

ChangeOwner sets the owner of n to newOwner

func (*Node) CheckLock

func (n *Node) CheckLock(ctx context.Context) error

CheckLock compares the context lock with the node lock

func (*Node) Child

func (n *Node) Child(ctx context.Context, name string) (*Node, error)

Child returns the child node with the given name

func (*Node) FindStorageSpaceRoot

func (n *Node) FindStorageSpaceRoot() error

FindStorageSpaceRoot calls n.Parent() and climbs the tree until it finds the space root node and adds it to the node

func (*Node) GetDTime

func (n *Node) GetDTime() (tmTime time.Time, err error)

GetDTime reads the dtime from the extended attributes

func (*Node) GetMetadata

func (n *Node) GetMetadata(key string) (val string, err error)

GetMetadata reads the metadata for the given key

func (*Node) GetTMTime

func (n *Node) GetTMTime() (tmTime time.Time, err error)

GetTMTime reads the tmtime from the extended attributes

func (*Node) GetTreeSize

func (n *Node) GetTreeSize() (treesize uint64, err error)

GetTreeSize reads the treesize from the extended attributes

func (*Node) HasPropagation

func (n *Node) HasPropagation() (propagation bool)

HasPropagation checks if the propagation attribute exists and is set to "1"

func (*Node) InternalPath

func (n *Node) InternalPath() string

InternalPath returns the internal path of the Node

func (*Node) IsDir added in v2.6.1

func (n *Node) IsDir() bool

IsDir returns true if the note is a directory

func (*Node) IsDisabled

func (n *Node) IsDisabled() bool

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) ListGrantees

func (n *Node) ListGrantees(ctx context.Context) (grantees []string, err error)

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

func (n *Node) ListGrants(ctx context.Context) ([]*provider.Grant, error)

ListGrants lists all grants of the current node.

func (*Node) LockFilePath

func (n *Node) LockFilePath() string

LockFilePath returns the internal path of the lock file of the node

func (*Node) Owner

func (n *Node) Owner() *userpb.UserId

Owner returns the space owner

func (*Node) Parent

func (n *Node) Parent() (p *Node, err error)

Parent returns the parent node

func (*Node) ParentInternalPath

func (n *Node) ParentInternalPath() string

ParentInternalPath returns the internal path of the parent of the current node

func (*Node) PermissionSet

func (n *Node) PermissionSet(ctx context.Context) provider.ResourcePermissions

PermissionSet returns the permission set for the current user the parent nodes are not taken into account

func (*Node) ReadGrant

func (n *Node) ReadGrant(ctx context.Context, grantee string) (g *provider.Grant, err error)

ReadGrant reads a CS3 grant

func (Node) ReadLock

func (n Node) ReadLock(ctx context.Context, skipFileLock bool) (*provider.Lock, error)

ReadLock reads the lock id for a node

func (*Node) ReadUserPermissions

func (n *Node) ReadUserPermissions(ctx context.Context, u *userpb.User) (ap provider.ResourcePermissions, err error)

ReadUserPermissions will assemble the permissions for the current user on the given node without parent nodes

func (*Node) RefreshLock

func (n *Node) RefreshLock(ctx context.Context, lock *provider.Lock) error

RefreshLock refreshes the node's lock

func (*Node) RemoveMetadata

func (n *Node) RemoveMetadata(key string) (err error)

RemoveMetadata removes a given key

func (*Node) SetChecksum

func (n *Node) SetChecksum(csType string, h hash.Hash) (err error)

SetChecksum writes the checksum with the given checksum type to the extended attributes

func (*Node) SetDTime

func (n *Node) SetDTime(t *time.Time) (err error)

SetDTime writes the UTC dtime to the extended attributes or removes the attribute if nil is passed

func (*Node) SetEtag

func (n *Node) SetEtag(ctx context.Context, val string) (err error)

SetEtag sets the temporary etag of a node if it differs from the current etag

func (*Node) SetFavorite

func (n *Node) SetFavorite(uid *userpb.UserId, val string) error

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) SetLock

func (n *Node) SetLock(ctx context.Context, lock *provider.Lock) error

SetLock sets a lock on the node

func (*Node) SetMetadata

func (n *Node) SetMetadata(key string, val string) (err error)

SetMetadata populates a given key with its value. Note that consumers should be aware of the metadata options on xattrs.go.

func (*Node) SetMtime

func (n *Node) SetMtime(ctx context.Context, mtime string) error

SetMtime sets the mtime and atime of a node

func (*Node) SetTMTime

func (n *Node) SetTMTime(t *time.Time) (err error)

SetTMTime writes the UTC tmtime to the extended attributes or removes the attribute if nil is passed

func (*Node) SetTreeSize

func (n *Node) SetTreeSize(ts uint64) (err error)

SetTreeSize writes the treesize to the extended attributes

func (*Node) Unlock

func (n *Node) Unlock(ctx context.Context, lock *provider.Lock) error

Unlock unlocks the node

func (*Node) UnsetTempEtag

func (n *Node) UnsetTempEtag() (err error)

UnsetTempEtag removes the temporary etag attribute

func (*Node) WriteAllNodeMetadata

func (n *Node) WriteAllNodeMetadata() (err error)

WriteAllNodeMetadata writes the Node metadata to disk

func (*Node) WriteOwner

func (n *Node) WriteOwner(owner *userpb.UserId) error

WriteOwner writes the space owner

type PathLookup

type PathLookup interface {
	InternalRoot() string
	InternalPath(spaceID, nodeID string) string
	Path(ctx context.Context, n *Node) (path string, err error)
	ShareFolder() string
}

PathLookup defines the interface for the lookup component

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) HasPermission

func (p *Permissions) HasPermission(ctx context.Context, n *Node, check func(*provider.ResourcePermissions) bool) (can bool, err error)

HasPermission call check() for every node up to the root until check returns true

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL