Documentation
¶
Overview ¶
Package file implements a backend.Backend over a local directory tree. Keys map to files under a root; writes are atomic (temp file + rename) so a reader never observes a partially written object — the property the "manifest written last" part commit relies on (DESIGN.md §8, _ref/docs/storage-engine.md §2).
Index ¶
- type File
- func (f *File) CreateObject(_ context.Context, key string) (backend.ObjectWriter, error)
- func (f *File) Delete(_ context.Context, key string) error
- func (f *File) FreeSpace(context.Context) (int64, error)
- func (*File) IsEphemeral() bool
- func (f *File) List(_ context.Context, prefix string) ([]string, error)
- func (f *File) PutIfAbsent(_ context.Context, key string, data []byte) (written bool, rerr error)
- func (f *File) Read(_ context.Context, key string) ([]byte, error)
- func (f *File) ReadAt(_ context.Context, key string, off, n int64) ([]byte, error)
- func (f *File) Size(_ context.Context, key string) (int64, error)
- func (f *File) Write(_ context.Context, key string, data []byte) (rerr error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a directory-backed backend.Backend. Keys are slash-delimited and map to paths under root. Safe for concurrent use (the filesystem serializes renames; reads and writes touch distinct temp files).
func (*File) CreateObject ¶ added in v0.37.0
CreateObject builds key's object incrementally in the temp file that File.Write uses for its whole-object write, renaming it over the final path on commit. Nothing is visible under key until then, so the atomicity contract is the same one; the difference is only that the bytes reach the filesystem as they are produced rather than all at once. Implements backend.ObjectCreator.
func (*File) Delete ¶
Delete removes key, or returns an backend.ErrNotExist-wrapping error if absent.
func (*File) FreeSpace ¶ added in v0.37.0
FreeSpace reports the bytes available on the filesystem holding the root directory. It takes the unprivileged figure, so the reserved root allowance is never counted as usable.
func (*File) IsEphemeral ¶
IsEphemeral reports false: data persists on disk.
func (*File) List ¶
List returns, sorted ascending, every key with the given prefix.
The prefix bounds the work, not just the result: keys map to paths, so only the subtree under the prefix's directory component is traversed, and within it only the children whose name can still extend into the prefix's final (possibly partial) segment.
func (*File) PutIfAbsent ¶
PutIfAbsent stores data under key only if it does not already exist, returning whether the write happened. It writes a temp file then hard-links it to the final path: os.Link fails with EEXIST if the destination exists, giving an atomic, exclusive create (the conditional commit primitive). A reader never sees a partial object — the link publishes a fully written file.
func (*File) Read ¶
Read returns the value stored under key, or an backend.ErrNotExist-wrapping error.
func (*File) ReadAt ¶ added in v0.37.0
ReadAt returns the object's [off, off+n) range, clamped to its end, with one pread — the file backend never maps a part column into memory to hand back a slice of it. Implements backend.ReaderAt.
func (*File) Size ¶ added in v0.12.0
Size returns the byte size of the object stored under key (os.Stat, no read), or an backend.ErrNotExist-wrapping error if absent. It implements backend.Sizer.