fileaccess

package
v0.4.122 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fileaccess says what one request of the file API may reach: the box's roots ([file] ManagementRoots, fileroots.Default) for the owner and the box's own services, and, for an account of role user, only the folders the owner gave it, a write only in the ones it may write (CasaOS#168).

The Gateway opens Files to an account with at least one folder, but it does not see the paths of a call (bodies, multipart uploads): this is where they are held to the folders, with the same openat2 resolution as the box's roots (a link or `..` does not lead out).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRoleUnknown: user-service has not said yet what the account is; asked again shortly.
	ErrRoleUnknown = errors.New("the account's role is not known yet: try again in a moment")
	// ErrAccountGone: the account was deleted.
	ErrAccountGone = errors.New("this account no longer exists")
	// ErrNoFolder: no folder of Files is given to the account.
	ErrNoFolder = errors.New("no folder of Files is given to this account")
	// ErrReadOnly: the account may read this folder, not change it.
	ErrReadOnly = errors.New("this folder is read-only for this account")
)
View Source
var (
	AccountOf = external.Account
	FoldersOf = external.FoldersOf
)

AccountOf and FoldersOf are what user-service says of an account (variables for the tests of this package and of the routes).

View Source
var ErrNotAFileOrFolder = errors.New("this is neither a file nor a folder")

ErrNotAFileOrFolder is a device, a pipe or a socket: not read for an account.

View Source
var ErrPathNotRooted = errors.New("this is not open to an account")

ErrPathNotRooted is a route that does not yet reach an account's folders through their root: it is not open to an account (see Pin and Root).

View Source
var Owner = &Scope{}

Owner reaches what the box's roots allow.

Functions

This section is empty.

Types

type Intent

type Intent int

Intent is what a path is reached for.

const (
	Read Intent = iota
	Write
)

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope is what one request may reach.

func For

func For(runtimePath, userID string, internal bool) (*Scope, error)

For is the scope of a request: internal (the box's own services) or the owner's account reach the box's roots; an account of role user reaches its folders only. Closed when user-service has no fresh answer: a role not known is ErrRoleUnknown, never taken as the owner's, and a user's folders are none unless the answer is fresh.

No userID is the box's own: the token check sets it on every signed-in request, and is skipped only for an internal one.

func (*Scope) Check

func (s *Scope) Check(intent Intent, paths ...*string) error

Check replaces each *path with its canonical spelling once it is below the box's roots and, for an account, below one of its folders (a writable one for Write).

func (*Scope) CheckEntries

func (s *Scope) CheckEntries(paths ...*string) error

CheckEntries is for what deletes, renames or moves the entry itself: its folder is checked, not what it leads to, and a root (an account's folder itself) is refused. An account needs a writable folder.

func (*Scope) FolderOf

func (s *Scope) FolderOf(p string) (folder, rel string)

FolderOf is the account's folder that holds the canonical path p (as Check gives it), and p relative to it ("." for the folder itself); "" when none does.

func (*Scope) Listing

func (s *Scope) Listing() *fileroots.Roots

Listing is the roots a listing follows: above them, a folder shows only the way down.

func (*Scope) Pin

func (s *Scope) Pin(p string) (pinned string, f *os.File, err error)

Pin opens p for reading, for an account through the root of its folder, and gives the path that reaches that very file or folder from now on: /proc/self/fd/N, which a later rename does not move. The caller closes f once it is done with pinned.

func (*Scope) Readable

func (s *Scope) Readable() []string

Readable and Writable are the account's folders; nil for the owner.

func (*Scope) Root

func (s *Scope) Root(intent Intent, p string, entry bool) (root *os.Root, folder, rel string, err error)

Root is, for an account, the os.Root of its folder that holds p, and p relative to it, once p passes Check (CheckEntries for an entry renamed or deleted). Whatever is renamed after, an operation through the root stays in the folder. folder is the folder's path.

func (*Scope) User

func (s *Scope) User() bool

User says whether the scope is an account's folders rather than the box's roots.

func (*Scope) Writable

func (s *Scope) Writable() []string

Jump to

Keyboard shortcuts

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