Documentation ¶
Overview ¶
Package fs contains an OCFL filesystem driver, intended for reading and writing OCFL present on physical filesystems
Index ¶
Constants ¶
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 ¶
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 ¶
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 ¶
Passthrough is a basic PathFunc for creating filesystem paths that are identical to the input, except with ant leading solidus removed.
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 ¶
NewDriver initializes a new filesystem OCFL driver with the given OCFL root directory.
func (*Driver) Open ¶
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.
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.