volfile

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 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 volfile reads and writes the files of a mounted volume.

What a volume holds is its user's, a symbolic link to a file of the node included, and this code runs as root: the root of the volume confines what is opened, so nothing here leads out of it.

Index

Constants

View Source
const (

	// MaxList is the most entries a listing returns, the first by name.
	MaxList = 1000

	// TypeFile, TypeDir and TypeLink are the types of the entries a listing
	// returns. Sockets, fifos and devices are left out.
	TypeFile = "file"
	TypeDir  = "dir"
	TypeLink = "link"
)
View Source
const (
	// UploadAttr is the extended attribute marking a file uploaded.
	UploadAttr = "user.opensvc.upload"

	// InstallAttr is the extended attribute marking a file a datastore
	// install writes, an InstallMark.
	InstallAttr = "user.opensvc.install"
)

Variables

View Source
var (
	// ErrFull is a file not fitting in the size of a volume.
	ErrFull = errors.New("volume full")

	// ErrExists is a file of the name existing, an upload not to replace it,
	// or a directory to make.
	ErrExists = errors.New("file exists")

	// ErrInvalidDir is a directory leading out of the volume, or hidden.
	ErrInvalidDir = errors.New("invalid directory")

	// ErrNoDir is a directory not existing.
	ErrNoDir = errors.New("no such directory")

	// ErrNotDir is a directory that is something else.
	ErrNotDir = errors.New("not a directory")

	// ErrNotEmpty is a directory to remove holding something.
	ErrNotEmpty = errors.New("directory not empty")

	// ErrNotFile is an entry to read that is no regular file: a link is
	// not followed.
	ErrNotFile = errors.New("not a file")

	// ErrInstalled is a file a datastore install writes, an upload not to
	// replace, replace or not.
	ErrInstalled = errors.New("installed file")

	// ErrUncounted is a volume of too many files to count what it holds
	// within the budget of a transfer, which is not to go over its size.
	ErrUncounted = errors.New("too many files to count what the volume holds")
)

Functions

func CleanDir

func CleanDir(s string) (string, error)

CleanDir returns a directory of a volume as the functions here take it, "." for the top: relative to the head, with no component leading up, nor hidden, which a listing leaves out.

func Exists

func Exists(head, dir, name string) (bool, error)

Exists says an entry of the name is in the directory, whatever it is.

func HasFilesystem

func HasFilesystem(head string) bool

HasFilesystem says a filesystem is mounted on head, which bounds what the volume holds: what it holds needs no count then.

func Install

func Install(head, dir, name string, r io.Reader, m InstallMark, perm fs.FileMode, uid, gid int) (err error)

Install writes r to the file of the name in the directory of the volume mounted on head, as an install fetching it from a url does: the file is marked with m, and given perm and the owner uid and gid, -1 leaving the one of the agent.

The file is written aside, at the top of the volume under the name a transfer takes, which a listing hides and the count of what the volume holds sees, and renamed over the file of the name once complete: what reads it sees the former file or the new one, never part of one. A reader failing, as a fetch cut, found over its size or not of its checksum, leaves the former file as it is, and nothing aside.

The owner, the mode and the mark are set on the file opened, never through a path a link of the volume could lead elsewhere, and the rename holds the lock of the volume an upload ending looks for the mark under: none replaces the file in between. A link of the name is replaced, not followed. The directory is to exist: an install makes it, with the mode and the owner its line says.

func InstalledReason

func InstalledReason(name string, m InstallMark) string

InstalledReason says why an upload does not replace the installed file of the name, and what to change instead: the key of the datastore it is written from, or the url it is fetched from.

func IsName

func IsName(s string) bool

IsName says a name is the one of an entry of a directory: no path, and not what a listing leaves out.

func Lock

func Lock(head string) (func(), error)

Lock takes the lock of the volume mounted on head an upload ending and an install writing a file hold, and returns what releases it: the directory itself is locked, nothing is written in the volume.

func Lstat

func Lstat(head, dir, name string) (os.FileInfo, error)

Lstat returns what the entry of the name in the directory is, a link not followed.

func Mkdir

func Mkdir(head, dir, name string) error

Mkdir makes the directory of the name in the directory, and no parent.

func Open

func Open(head, dir, name string) (*os.File, error)

Open opens the file of the name in the directory for reading, a link not followed: the file opened is the one Lstat said was a regular file.

func Remove

func Remove(head, dir, name string) error

Remove removes the entry of the name in the directory: a file, a link but not what it leads to, or an empty directory.

func Stat

func Stat(head, dir, name string) (os.FileInfo, error)

Stat returns what the entry of the name in the directory is, not following a link, ErrNotFile when it is no regular file.

func Write

func Write(head, dir, name string, r io.Reader, size int64, upload Upload) (err error)

Write writes r to the file of the name in the directory, the files of the volume and the transfers running with it holding size bytes at most, or as much as r says when size is negative. The file is written aside, to appear complete or not, and marked uploaded.

What the volume holds is read as the transfer begins and as it ends, and what the other transfers write as it goes: they run in processes of their own, each of which would otherwise count on the same room.

A file of the name existing as the transfer ends is ErrExists, unless the upload replaces it: the file comes by a link of its own name, which the kernel refuses to an existing one, where a rename would replace it.

Types

type Info

type Info struct {
	Name       string
	Type       string
	Size       int64
	ModifiedAt time.Time
	UploadedBy string
	UploadedAt time.Time
	Installed  *InstallMark
	Target     string
}

Info is what a listing says of an entry. UploadedBy and UploadedAt are the mark of an upload, empty for a file not uploaded, or on a filesystem not keeping it, and Installed the mark of a datastore install. Target is what a link says, never followed.

type InstallMark

type InstallMark struct {
	From string    `json:"from"`
	Key  string    `json:"key,omitempty"`
	At   time.Time `json:"at"`

	// SHA256 is the digest of the content Install wrote, which a later
	// install compares the file with: a file changed since is installed
	// again.
	SHA256 string `json:"sha256,omitempty"`
}

InstallMark is what a file an install writes is marked with: the datastore and its key, or the url fetched, which has no key, and when. An upload does not replace such a file, which the next install would write again: the key, or the url, is what to change.

func Installed

func Installed(head, dir, name string) (m InstallMark, ok bool, err error)

Installed returns the mark of the install of the entry of the name in the directory, ok false when it has none.

type Listing

type Listing struct {
	Items     []Info
	Truncated bool
}

Listing is the entries of a directory, the first MaxList by name, and whether there are more.

func List

func List(head, dir string) (Listing, error)

List returns the entries of the directory, the hidden ones left out.

type Upload

type Upload struct {
	By      string
	Replace bool
}

Upload says how a file is written: who sends it, and whether it replaces a file of its name.

Jump to

Keyboard shortcuts

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