filestore

package
v2.4.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2019 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileDoesNotExist = errors.New("file does not exist")
	ErrNotInUploading   = errors.New("file not stored in 'uploading' storage")
)

Predefined errors

Functions

func CleanupTestStore

func CleanupTestStore(store *Store)

CleanupTestStore deletes a store returned by CreateTestStore()

func LinkTestFileStore

func LinkTestFileStore(cloneTo string)

LinkTestFileStore creates a copy of _test_file_store by hard-linking files into a temporary directory. Panics if there are any errors.

Types

type FileStatus

type FileStatus int

FileStatus represents the status of a file in the store.

const (
	StatusNotSet FileStatus = iota
	StatusDoesNotExist
	StatusUploading
	StatusStored
)

Valid statuses for files in the store.

type Storage

type Storage interface {
	// ResolveFile checks the status of the file in the store and returns the actual path.
	ResolveFile(checksum string, filesize int64, storedOnly StoredOnly) (string, FileStatus)

	// OpenForUpload returns a file pointer suitable to stream an uploaded file to.
	OpenForUpload(checksum string, filesize int64) (*os.File, error)

	// BasePath returns the directory path of the storage.
	// This is the directory containing the 'stored' and 'uploading' directories.
	BasePath() string

	// StoragePath returns the directory path of the 'stored' storage bin.
	StoragePath() string

	// MoveToStored moves a file from 'uploading' storage to the actual 'stored' storage.
	MoveToStored(checksum string, filesize int64, uploadedFilePath string) error

	// RemoveUploadedFile removes a file from the 'uploading' storage.
	// This is intended to clean up files for which upload was aborted for some reason.
	RemoveUploadedFile(filePath string)

	// RemoveStoredFile removes a file from the 'stored' storage bin.
	// This is intended to garbage collect old, unused files.
	RemoveStoredFile(filePath string) error
}

Storage is the interface for Shaman file stores.

func New

func New(conf config.Config) Storage

New returns a new file store.

type Store

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

Store represents the default Shaman file store.

func CreateTestStore

func CreateTestStore() *Store

CreateTestStore returns a Store that can be used for unit testing.

func (*Store) BasePath

func (s *Store) BasePath() string

BasePath returns the directory path of the storage.

func (*Store) MoveToStored

func (s *Store) MoveToStored(checksum string, filesize int64, uploadedFilePath string) error

MoveToStored moves a file from 'uploading' to 'stored' storage. It is assumed that the checksum and filesize have been verified.

func (*Store) MustStoreFileForTest

func (s *Store) MustStoreFileForTest(checksum string, filesize int64, contents []byte)

MustStoreFileForTest allows a unit test to store some file in the 'stored' storage bin. Any error will cause a panic.

func (*Store) OpenForUpload

func (s *Store) OpenForUpload(checksum string, filesize int64) (*os.File, error)

OpenForUpload returns a file pointer suitable to stream an uploaded file to.

func (*Store) RemoveStoredFile

func (s *Store) RemoveStoredFile(filePath string) error

RemoveStoredFile removes a file from the 'stored' storage bin.

func (*Store) RemoveUploadedFile

func (s *Store) RemoveUploadedFile(filePath string)

RemoveUploadedFile removes a file from the 'uploading' storage bin. Errors are ignored.

func (*Store) ResolveFile

func (s *Store) ResolveFile(checksum string, filesize int64, storedOnly StoredOnly) (path string, status FileStatus)

ResolveFile checks the status of the file in the store.

func (*Store) StoragePath

func (s *Store) StoragePath() string

StoragePath returns the directory path of the 'stored' storage bin.

type StoredOnly

type StoredOnly bool

StoredOnly indicates whether to resolve only 'stored' files or also 'uploading' or 'checking'.

const (
	ResolveStoredOnly StoredOnly = true
	ResolveEverything StoredOnly = false
)

For the ResolveFile() call. This is more explicit than just true/false values.

Jump to

Keyboard shortcuts

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