Documentation ¶
Index ¶
- Variables
- func CleanupTestStore(store *Store)
- func LinkTestFileStore(cloneTo string)
- type FileStatus
- type Storage
- type Store
- func (s *Store) BasePath() string
- func (s *Store) MoveToStored(checksum string, filesize int64, uploadedFilePath string) error
- func (s *Store) MustStoreFileForTest(checksum string, filesize int64, contents []byte)
- func (s *Store) OpenForUpload(checksum string, filesize int64) (*os.File, error)
- func (s *Store) RemoveStoredFile(filePath string) error
- func (s *Store) RemoveUploadedFile(filePath string)
- func (s *Store) ResolveFile(checksum string, filesize int64, storedOnly StoredOnly) (path string, status FileStatus)
- func (s *Store) StoragePath() string
- type StoredOnly
Constants ¶
This section is empty.
Variables ¶
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.
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) MoveToStored ¶
MoveToStored moves a file from 'uploading' to 'stored' storage. It is assumed that the checksum and filesize have been verified.
func (*Store) MustStoreFileForTest ¶
MustStoreFileForTest allows a unit test to store some file in the 'stored' storage bin. Any error will cause a panic.
func (*Store) OpenForUpload ¶
OpenForUpload returns a file pointer suitable to stream an uploaded file to.
func (*Store) RemoveStoredFile ¶
RemoveStoredFile removes a file from the 'stored' storage bin.
func (*Store) RemoveUploadedFile ¶
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 ¶
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.