fs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package fs contains an OCFL filesystem driver, intended for reading and writing OCFL present on physical filesystems

Index

Constants

View Source
const AtomicPrefix = ".ocfl.atomic."

AtomicPrefix is a file prefix for temporary files that are created during AtomicWrite

Variables

This section is empty.

Functions

func LocateRoot

func LocateRoot(loc string) (string, error)

LocateRoot attempts find the first directory matching an OCFL root in the given directory, or any parent directories. The primary use case is finding the identity of the ocfl root when given the location of some file somewhere within it.

func MkRoot

func MkRoot(path string) (err error)

InitRoot initializes an OCFL root at the given path. If the path does not exist, it creates a directory. If the path is an empty directory, it will place an OCFL Namaste file in it. IIf the path is already a root, this is a noop. For all other cases (e.g. it's a file, or a non-existent directory), an error will be thrown)

func Passthrough

func Passthrough(id string) string

Passthrough is a basic PathFunc for creating filesystem paths that are identical to the input, except with ant leading solidus removed.

func ReadInventory

func ReadInventory(objPath string) (*metadata.Inventory, error)

ReadInventory reads the inventory of an OCFL object, given the path of an OCFL object root directory

Types

type Config

type Config struct {
	Root        string           // OCFL root directory
	ObjectPaths fspath.Generator // OCFL object directories based on id
	FilePaths   fspath.Generator // physical file paths based on logical path
}

Config encapsulates an OCFL filesystem driver config.

Object and file path functions are mandatory whenever the Driver will be used for writes, and are optional for reads. That being said, if an ObjectPathFunc is provided, it will be used for quick lookups of OCFL object directories. If not provided, the driver will perform a brute force search through the directory tree when it needs to perform lookups of OCFL directories when given an object ID.

type Driver

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

Driver represents the filesystem driver for OCFL

func NewDriver

func NewDriver(cfg Config) (*Driver, error)

NewDriver initializes a new filesystem OCFL driver with the given OCFL root directory.

func (*Driver) Open

func (d *Driver) Open(id string, opts ocfl.Options) (sess ocfl.Session, err error)

Open creates a session providing read/write access to the specified OCFL object.

For sessions that write content by creating or updating versions of OCFL objects, this implementation uses atomic renames to guarantee that inventory files (old, or new) never reference files that do not exist. Crashes or other errors are allowed to create "garbage" in the form of files that are not referenced by any inventory file. These files may be safely removed as part of a cleanup process.

func (*Driver) Walk

func (d *Driver) Walk(desired ocfl.Select, cb func(ocfl.EntityRef) error, loc ...string) error

Walk crawls the filesystem from a given starting point (physical path, or logical ID), and invokes a callback that matches the criteria provided in the given selector.

type ManagedWrite

type ManagedWrite struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

ManagedWrite encapsulates an io.WriteCloser such that the write can be rolled back upon error.

func AtomicWrite

func AtomicWrite(path string) (*ManagedWrite, error)

AtomicWrite creates a temporary file which is opened for write (only), in the same directory as the specified path. Once written and closed, it atomically renames the temp file to match the given path.

Note, Close() may fail. If it does, it is up to the caller to determine the appropriate response (e.g. Rollback(), or log it and manually inspect)

func SafeWrite

func SafeWrite(path string) (*ManagedWrite, error)

SafeWrite attempts to create a file at the given path to write to. If a file already exists there, it'll do an AtomicWrite which writes to a temporary file, and atomically renames when successful.

func (*ManagedWrite) Close

func (w *ManagedWrite) Close() error

Close frees up any resources and performs the necessary actions to commit the write.

func (*ManagedWrite) Rollback

func (w *ManagedWrite) Rollback() error

Rollback attempts to undo any tangible effects of an incomplete/errored write.

type TeeWriter

type TeeWriter struct {
	io.Writer           // Destination
	Tee       io.Writer // Bytes get cc'd to the tee
}

TeeWriter passes along bytes to a given "Tee" writer as it writes to a Destination writer.

func (*TeeWriter) Write

func (t *TeeWriter) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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