filestore

package
v0.0.0-...-dfed899 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

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 in a temporary directory. Panics if there are any errors.

func TempFile

func TempFile(dir, pattern string) (f *os.File, err error)

TempFile creates a new temporary file in the directory dir, opens the file for reading and writing, and returns the resulting *os.File. The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.

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.

func (FileStatus) String

func (fs FileStatus) String() string

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 New

func New(conf config.Config) *Store

New returns a new file store.

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