node

package
v2.26.7 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockdiscoveryKey = "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"

	// ProcessingStatus is the name of the status when processing a file
	ProcessingStatus = "processing:"
)

Define keys and values used in the node metadata

Variables

View Source
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

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

func CalculateChecksums added in v2.20.0

func CalculateChecksums(ctx context.Context, path string) (hash.Hash, hash.Hash, hash.Hash32, error)

CalculateChecksums calculates the sha1, md5 and adler32 checksums of a file

func CalculateEtag

func CalculateEtag(id 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 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 ServiceAccountPermissions added in v2.17.0

func ServiceAccountPermissions() *provider.ResourcePermissions

ServiceAccountPermissions defines the permissions for nodes when requested by a service account

func ShareFolderPermissions

func ShareFolderPermissions() *provider.ResourcePermissions

ShareFolderPermissions defines permissions for the shared jail

Types

type Attributes added in v2.13.0

type Attributes map[string][]byte

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

func (Attributes) Time added in v2.20.0

func (md Attributes) Time(key string) (time.Time, error)

Time reads a time value

func (Attributes) UInt64 added in v2.16.0

func (md Attributes) UInt64(key string) (uint64, error)

UInt64 reads an uint64 value

type IDCacher added in v2.20.0

type IDCacher interface {
	CacheID(ctx context.Context, spaceID, nodeID, val string) error
	GetCachedID(ctx context.Context, spaceID, nodeID string) (string, bool)
}

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) 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) DeleteGrant added in v2.16.0

func (n *Node) DeleteGrant(ctx context.Context, g *provider.Grant, acquireLock bool) (err error)

ReadGrant reads a CS3 grant

func (*Node) FindStorageSpaceRoot

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

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

func (n *Node) GetBlobSize(ctx context.Context) (treesize uint64, err error)

GetBlobSize reads the blobsize from the extended attributes

func (*Node) GetDTime

func (n *Node) GetDTime(ctx context.Context) (time.Time, error)

GetDTime reads the dmtime from the extended attributes

func (*Node) GetMTime added in v2.13.0

func (n *Node) GetMTime(ctx context.Context) (time.Time, error)

GetMTime reads the mtime from the extended attributes

func (*Node) GetTMTime

func (n *Node) GetTMTime(ctx context.Context) (time.Time, error)

GetTMTime reads the tmtime from the extended attributes

func (*Node) GetTreeSize

func (n *Node) GetTreeSize(ctx context.Context) (treesize uint64, err error)

GetTreeSize reads the treesize from the extended attributes

func (*Node) HasPropagation

func (n *Node) HasPropagation(ctx context.Context) (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) IsDenied added in v2.11.0

func (n *Node) IsDenied(ctx context.Context) bool

IsDenied checks if the node was denied to that user

func (*Node) IsDir added in v2.6.1

func (n *Node) IsDir(ctx context.Context) bool

IsDir returns true if the node is a directory

func (*Node) IsDisabled

func (n *Node) IsDisabled(ctx context.Context) 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) IsProcessing added in v2.13.0

func (n *Node) IsProcessing(ctx context.Context) bool

IsProcessing returns true if the node is currently being processed

func (*Node) IsSpaceRoot added in v2.12.0

func (n *Node) IsSpaceRoot(ctx context.Context) bool

IsSpaceRoot checks if the node is a space root

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) MarshalJSON added in v2.25.0

func (n *Node) MarshalJSON() ([]byte, error)

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

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

Owner returns the space owner

func (*Node) Parent

func (n *Node) Parent(ctx context.Context) (p *Node, err error)

Parent returns the parent node

func (*Node) ParentPath added in v2.13.0

func (n *Node) ParentPath() string

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

func (*Node) ParentWithReader added in v2.13.3

func (n *Node) ParentWithReader(ctx context.Context, r io.Reader) (*Node, error)

ParentWithReader returns the parent node

func (*Node) PermissionSet

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

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) ProcessingID added in v2.19.6

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

ProcessingID returns the latest upload session id

func (*Node) Purge added in v2.18.0

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

Purge removes a node from disk. It does not move it to the trash

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, 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

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

RefreshLock refreshes the node's lock

func (*Node) RemoveXattr added in v2.12.0

func (n *Node) RemoveXattr(ctx context.Context, key string, acquireLock bool) error

RemoveXattr removes an extended attribute from the write-through cache/node

func (*Node) ScanData added in v2.13.0

func (n *Node) ScanData(ctx context.Context) (scanned bool, virus string, scantime time.Time)

ScanData returns scanning information of the node

func (*Node) SetChecksum

func (n *Node) SetChecksum(ctx context.Context, 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(ctx context.Context, t *time.Time) (err error)

SetDTime writes the UTC dmtime 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(ctx context.Context, 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) SetMtime

func (n *Node) SetMtime(ctx context.Context, t *time.Time) (err error)

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

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

SetMtimeString sets the mtime and atime of a node to the unixtime parsed from the given string

func (*Node) SetOwner added in v2.13.0

func (n *Node) SetOwner(owner *userpb.UserId)

SetOwner sets the space owner on the node

func (*Node) SetScanData added in v2.13.0

func (n *Node) SetScanData(ctx context.Context, info string, date time.Time) error

SetScanData sets the virus scan info to the node

func (*Node) SetTMTime

func (n *Node) SetTMTime(ctx context.Context, 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(ctx context.Context, ts uint64) (err error)

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

func (n *Node) SetXattr(ctx context.Context, key string, val []byte) (err error)

SetXattr sets an extended attribute on the write-through cache/node

func (*Node) SetXattrString added in v2.13.0

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

SetXattrString sets a string extended attribute on the write-through cache/node

func (*Node) SetXattrs added in v2.12.0

func (n *Node) SetXattrs(attribs map[string][]byte, acquireLock bool) (err error)

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

func (n *Node) SpaceOwnerOrManager(ctx context.Context) *userpb.UserId

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

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

Unlock unlocks the node

func (*Node) UnmarkProcessing added in v2.13.0

func (n *Node) UnmarkProcessing(ctx context.Context, uploadID string) error

UnmarkProcessing removes the processing flag from the node

func (*Node) UnsetTempEtag

func (n *Node) UnsetTempEtag(ctx context.Context) (err error)

UnsetTempEtag removes the temporary etag attribute

func (*Node) Xattr added in v2.12.0

func (n *Node) Xattr(ctx context.Context, key string) ([]byte, error)

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

func (n *Node) XattrInt32(ctx context.Context, key string) (int32, error)

XattrInt32 returns the int32 representation of an attribute

func (*Node) XattrInt64 added in v2.13.0

func (n *Node) XattrInt64(ctx context.Context, key string) (int64, error)

XattrInt64 returns the int64 representation of an attribute

func (*Node) XattrString added in v2.13.0

func (n *Node) XattrString(ctx context.Context, key string) (string, error)

XattrString returns the string representation of an attribute

func (*Node) XattrUint64 added in v2.15.0

func (n *Node) XattrUint64(ctx context.Context, key string) (uint64, error)

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

func (n *Node) XattrsWithReader(ctx context.Context, r io.Reader) (Attributes, error)

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 {
	NodeFromSpaceID(ctx context.Context, spaceID string) (n *Node, err error)
	NodeFromResource(ctx context.Context, ref *provider.Reference) (*Node, error)
	NodeFromID(ctx context.Context, id *provider.ResourceId) (n *Node, err error)

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

	GenerateSpaceID(spaceType string, owner *userpb.User) (string, error)

	InternalRoot() string
	InternalPath(spaceID, nodeID string) string
	Path(ctx context.Context, n *Node, hasPermission PermissionFunc) (path string, err error)
	MetadataBackend() metadata.Backend
	TimeManager() TimeManager
	ReadBlobIDAndSizeAttr(ctx context.Context, path string, attrs Attributes) (string, int64, error)
	TypeFromPath(ctx context.Context, path string) provider.ResourceType
	CopyMetadataWithSourceLock(ctx context.Context, sourcePath, targetPath string, filter func(attributeName string, value []byte) (newValue []byte, copy bool), lockedSource *lockedfile.File, acquireTargetLock bool) (err error)
	CopyMetadata(ctx context.Context, src, target string, filter func(attributeName string, value []byte) (newValue []byte, copy bool), acquireTargetLock bool) (err error)
}

PathLookup defines the interface for the lookup component

type PermissionFunc added in v2.13.0

type PermissionFunc func(*Node) bool

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

type TimeManager added in v2.25.0

type TimeManager interface {
	// OverrideMTime overrides the mtime of the node, either on the node itself or in the given attributes, depending on the implementation
	OverrideMtime(ctx context.Context, n *Node, attrs *Attributes, mtime time.Time) error

	// MTime returns the mtime of the node
	MTime(ctx context.Context, n *Node) (time.Time, error)
	// SetMTime sets the mtime of the node
	SetMTime(ctx context.Context, n *Node, mtime *time.Time) error

	// TMTime returns the tmtime of the node
	TMTime(ctx context.Context, n *Node) (time.Time, error)
	// SetTMTime sets the tmtime of the node
	SetTMTime(ctx context.Context, n *Node, tmtime *time.Time) error

	// CTime returns the ctime of the node
	CTime(ctx context.Context, n *Node) (time.Time, error)

	// DTime returns the deletion time of the node
	DTime(ctx context.Context, n *Node) (time.Time, error)
	// SetDTime sets the deletion time of the node
	SetDTime(ctx context.Context, n *Node, mtime *time.Time) error
}

type Tree added in v2.19.0

type Tree interface {
	Setup() error

	GetMD(ctx context.Context, node *Node) (os.FileInfo, error)
	ListFolder(ctx context.Context, node *Node) ([]*Node, error)
	// CreateHome(owner *userpb.UserId) (n *Node, err error)
	CreateDir(ctx context.Context, node *Node) (err error)
	TouchFile(ctx context.Context, node *Node, markprocessing bool, mtime string) error
	// CreateReference(ctx context.Context, node *Node, targetURI *url.URL) error
	Move(ctx context.Context, oldNode *Node, newNode *Node) (err error)
	Delete(ctx context.Context, node *Node) (err error)
	RestoreRecycleItemFunc(ctx context.Context, spaceid, key, trashPath string, target *Node) (*Node, *Node, func() error, error)
	PurgeRecycleItemFunc(ctx context.Context, spaceid, key, purgePath string) (*Node, func() error, error)

	InitNewNode(ctx context.Context, n *Node, fsize uint64) (metadata.UnlockFunc, error)

	WriteBlob(node *Node, source string) error
	ReadBlob(node *Node) (io.ReadCloser, error)
	DeleteBlob(node *Node) error

	BuildSpaceIDIndexEntry(spaceID, nodeID string) string
	ResolveSpaceIDIndexEntry(spaceID, entry string) (string, string, error)

	Propagate(ctx context.Context, node *Node, sizeDiff int64) (err error)
}

Tree is used to manage a tree hierarchy

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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