Documentation ¶
Index ¶
- Constants
- Variables
- func AddPermissions(l *provider.ResourcePermissions, r *provider.ResourcePermissions)
- func CalculateEtag(nodeID string, tmTime time.Time) (string, error)
- func GetAvailableSize(path string) (uint64, error)
- func IsSpaceRoot(r *Node) bool
- func NoOwnerPermissions() provider.ResourcePermissions
- func NoPermissions() provider.ResourcePermissions
- func OwnerPermissions() provider.ResourcePermissions
- func ReadBlobSizeAttr(path string) (int64, error)
- func ShareFolderPermissions() provider.ResourcePermissions
- type Node
- func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissions, mdKeys []string, ...) (ri *provider.ResourceInfo, err error)
- func (n *Node) ChangeOwner(new *userpb.UserId) (err error)
- func (n *Node) Child(ctx context.Context, name string) (*Node, error)
- func (n *Node) FindStorageSpaceRoot() error
- func (n *Node) GetTMTime() (tmTime time.Time, err error)
- func (n *Node) GetTreeSize() (treesize uint64, err error)
- func (n *Node) HasPropagation() (propagation bool)
- func (n *Node) InternalPath() string
- func (n *Node) ListGrantees(ctx context.Context) (grantees []string, err error)
- func (n *Node) Owner() (*userpb.UserId, error)
- func (n *Node) Parent() (p *Node, err error)
- func (n *Node) PermissionSet(ctx context.Context) provider.ResourcePermissions
- func (n *Node) ReadGrant(ctx context.Context, grantee string) (g *provider.Grant, err error)
- func (n *Node) ReadUserPermissions(ctx context.Context, u *userpb.User) (ap provider.ResourcePermissions, err error)
- func (n *Node) SetChecksum(csType string, h hash.Hash) (err error)
- func (n *Node) SetEtag(ctx context.Context, val string) (err error)
- func (n *Node) SetFavorite(uid *userpb.UserId, val string) error
- func (n *Node) SetMetadata(key string, val string) (err error)
- func (n *Node) SetMtime(ctx context.Context, mtime string) error
- func (n *Node) SetTMTime(t time.Time) (err error)
- func (n *Node) SetTreeSize(ts uint64) (err error)
- func (n *Node) UnsetTempEtag() (err error)
- func (n *Node) WriteMetadata(owner *userpb.UserId) (err error)
- type PathLookup
- type Permissions
Constants ¶
const ( FavoriteKey = "http://owncloud.org/ns/favorite" ChecksumsKey = "http://owncloud.org/ns/checksums" QuotaKey = "quota" QuotaUncalculated = "-1" QuotaUnknown = "-2" QuotaUnlimited = "-3" )
Define keys and values used in the node metadata
Variables ¶
var CheckQuota = func(spaceRoot *Node, fileSize uint64) (quotaSufficient bool, err error) { used, _ := spaceRoot.GetTreeSize() if !enoughDiskSpace(spaceRoot.InternalPath(), fileSize) { return false, errtypes.InsufficientStorage("disk full") } quotaByte, _ := xattr.Get(spaceRoot.InternalPath(), xattrs.QuotaAttr) var total uint64 if quotaByte == nil { return true, nil } total, _ = strconv.ParseUint(string(quotaByte), 10, 64) if fileSize > total-used || total < used { return false, errtypes.InsufficientStorage("quota exceeded") } return true, nil }
CheckQuota checks if both disk space and available quota are sufficient
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 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 ReadBlobSizeAttr ¶
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 { 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(id, parentID, name string, blobsize int64, blobID string, owner *userpb.UserId, lu PathLookup) *Node
New returns a new instance of Node
func (*Node) AsResourceInfo ¶
func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissions, mdKeys []string, returnBasename bool) (ri *provider.ResourceInfo, err error)
AsResourceInfo return the node as CS3 ResourceInfo
func (*Node) ChangeOwner ¶
ChangeOwner sets the owner of n to newOwner
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) 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) 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) Owner ¶
Owner returns the cached owner id or reads it from the extended attributes TODO can be private as only the AsResourceInfo uses it
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) 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) SetChecksum ¶
SetChecksum writes the checksum with the given checksum type to the extended attributes
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) SetMetadata ¶
SetMetadata populates a given key with its value. Note that consumers should be aware of the metadata options on xattrs.go.
func (*Node) SetTreeSize ¶
SetTreeSize writes the treesize to the extended attributes
func (*Node) UnsetTempEtag ¶
UnsetTempEtag removes the temporary etag attribute
type PathLookup ¶
type PathLookup interface { RootNode(ctx context.Context) (node *Node, err error) HomeOrRootNode(ctx context.Context) (node *Node, err error) InternalRoot() string InternalPath(ID string) string Path(ctx context.Context, n *Node) (path string, err error) }
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