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
- Variables
- func CleanDir(s string) (string, error)
- func Exists(head, dir, name string) (bool, error)
- func HasFilesystem(head string) bool
- func Install(head, dir, name string, r io.Reader, m InstallMark, perm fs.FileMode, ...) (err error)
- func InstalledReason(name string, m InstallMark) string
- func IsName(s string) bool
- func Lock(head string) (func(), error)
- func Lstat(head, dir, name string) (os.FileInfo, error)
- func Mkdir(head, dir, name string) error
- func Open(head, dir, name string) (*os.File, error)
- func Remove(head, dir, name string) error
- func Stat(head, dir, name string) (os.FileInfo, error)
- func Write(head, dir, name string, r io.Reader, size int64, upload Upload) (err error)
- type Info
- type InstallMark
- type Listing
- type Upload
Constants ¶
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" )
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 ¶
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 ¶
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 HasFilesystem ¶
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 ¶
IsName says a name is the one of an entry of a directory: no path, and not what a listing leaves out.
func Lock ¶
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 Open ¶
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 ¶
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 ¶
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 ¶
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.