fs

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

type FS struct {
}

FS implements the wal.VFS interface using GO's built in OS Filesystem (and a few helpers).

TODO if we changed the interface to be Dir centric we could cache the open dir handle and save some time opening it on each Create in order to fsync.

func New

func New() *FS

func (*FS) Create

func (fs *FS) Create(dir string, name string, size uint64) (types.WritableFile, error)

Create creates a new file with the given name. If a file with the same name already exists an error is returned. If a non-zero size is given, implementations should make a best effort to pre-allocate the file to be that size. The dir must already exist and be writable to the current process.

func (*FS) Delete

func (fs *FS) Delete(dir string, name string) error

Delete indicates the file is no longer required. Typically it should be deleted from the underlying system to free disk space.

func (*FS) ListDir

func (fs *FS) ListDir(dir string) ([]string, error)

ListDir returns a list of all files in the specified dir in lexicographical order. If the dir doesn't exist, it must return an error. Empty array with nil error is assumed to mean that the directory exists and was readable, but contains no files.

func (*FS) OpenReader

func (fs *FS) OpenReader(dir string, name string) (types.ReadableFile, error)

OpenReader opens an existing file in read-only mode. If the file doesn't exist or permission is denied, an error is returned, otherwise no checks are made about the well-formedness of the file, it may be empty, the wrong size or corrupt in arbitrary ways.

func (*FS) OpenWriter

func (fs *FS) OpenWriter(dir string, name string) (types.WritableFile, error)

OpenWriter opens a file in read-write mode. If the file doesn't exist or permission is denied, an error is returned, otherwise no checks are made about the well-formedness of the file, it may be empty, the wrong size or corrupt in arbitrary ways.

type File

type File struct {
	os.File
	// contains filtered or unexported fields
}

File wraps an os.File and implements types.WritableFile. It ensures that the first time Sync is called on the file, that the parent directory is also Fsynced to ensure a crash won't cause the FS to forget the file is there.

Postponing this allows us to ensure that we do the minimum necessary fsyncs but still ensure all required fsyncs are done by the time we acknowledge committed data in the new file.

func (*File) Sync

func (f *File) Sync() error

Sync calls fsync on the underlying file. If this is the first call to Sync since creation it also fsyncs the parent dir.

Jump to

Keyboard shortcuts

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