store

package
v0.0.0-...-3d10487 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: BSD-2-Clause, BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const FilePerm = ioFS.FileMode(0700)

FilePerm is the permissions used when creating files and directories. 700 means only the owner can see and modify files.

Variables

View Source
var (
	// NonLocalFileErr is returned when attempting to read or write to file or
	// directory outside the base directory.
	NonLocalFileErr = errors.New("file path not in local base directory")
)

Functions

This section is empty.

Types

type FileStore

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

FileStore manages the file storage in a base directory. Adheres to the Store interface.

func (*FileStore) GetLastModified

func (fs *FileStore) GetLastModified(path string) (time.Time, error)

GetLastModified returns the last modification time for the file at the given file.

Returns NonLocalFileErr if the file is outside the base path.

func (*FileStore) GetLastWrite

func (fs *FileStore) GetLastWrite() (time.Time, error)

GetLastWrite returns the time of the most recent successful Write operation that was performed.

func (*FileStore) Read

func (fs *FileStore) Read(path string) ([]byte, error)

Read reads from the provided file path and returns the data in the file at that path.

An error is returned if it fails to read the file. Returns NonLocalFileErr if the file is outside the base path.

func (*FileStore) ReadDir

func (fs *FileStore) ReadDir(path string) ([]string, error)

ReadDir reads the named directory, returning all its directory entries sorted by filename.

Returns NonLocalFileErr if the file is outside the base path.

func (*FileStore) Write

func (fs *FileStore) Write(path string, data []byte) error

Write writes the provided data to the file path.

An error is returned if the write fails. Returns NonLocalFileErr if the file is outside the base path.

type MemStore

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

MemStore manages the storage in a base directory. It saves everything in memory instead of to the file system. Adheres to the Store interface.

func (*MemStore) GetLastModified

func (ms *MemStore) GetLastModified(path string) (time.Time, error)

GetLastModified returns the last modification time for the file at the given file.

Returns NonLocalFileErr if the file is outside the base path.

func (*MemStore) GetLastWrite

func (ms *MemStore) GetLastWrite() (time.Time, error)

GetLastWrite returns the time of the most recent successful Write operation that was performed.

func (*MemStore) Read

func (ms *MemStore) Read(path string) ([]byte, error)

Read reads from the provided file path and returns the data in the file at that path.

An error is returned if it fails to read the file. Returns os.ErrNotExist if the file cannot be found.

func (*MemStore) ReadDir

func (ms *MemStore) ReadDir(path string) ([]string, error)

ReadDir reads the named directory, returning all its directory entries sorted by filename.

Returns NonLocalFileErr if the file is outside the base path.

func (*MemStore) Write

func (ms *MemStore) Write(path string, data []byte) error

Write writes the provided data to the file path. Does not return any errors.

type NewStore

type NewStore func(storageDir, baseDir string) (Store, error)

NewStore generates a new Store for the given base directory that will be created in the storage directory.

Returns NonLocalFileErr if the file is outside the storage directory.

type Store

type Store interface {
	// Read reads from the provided file path and returns the data in the file
	// at that path.
	//
	// An error is returned if it fails to read the file. Returns
	// [NonLocalFileErr] if the file is outside the base path.
	Read(path string) ([]byte, error)

	// Write writes the provided data to the file path.
	//
	// An error is returned if the write fails. Returns [NonLocalFileErr] if the
	// file is outside the base path.
	Write(path string, data []byte) error

	// GetLastModified returns the last modification time for the file at the
	// given file.
	//
	// Returns [NonLocalFileErr] if the file is outside the base path.
	GetLastModified(path string) (time.Time, error)

	// GetLastWrite returns the time of the most recent successful Write
	// operation that was performed.
	GetLastWrite() (time.Time, error)

	// ReadDir reads the named directory, returning all its directory entries
	// sorted by filename.
	//
	// Returns [NonLocalFileErr] if the file is outside the base path.
	ReadDir(path string) ([]string, error)
}

Store copies the [collective.RemoteStore] interface.

func NewFileStore

func NewFileStore(storageDir, baseDir string) (Store, error)

NewFileStore creates a new FileStore at the specified base directory. This function creates a new directory in the filesystem.

Returns NonLocalFileErr if the file is outside the storage directory.

func NewMemStore

func NewMemStore(_ string, _ string) (Store, error)

NewMemStore creates a new MemStore at the specified base directory.

Jump to

Keyboard shortcuts

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