Documentation
¶
Index ¶
Constants ¶
const DefaultDataFileName = "data"
DefaultDataFileName is the name of the actual blob data file.
const DefaultDirPermission = 0775
DefaultDirPermission is the default permission for new directories.
const DefaultShardIDLength = 2
DefaultShardIDLength is the number of bytes of file digest to be used for shard ID. For every byte (2 HEX char), one more level of directories will be created.
Variables ¶
var (
ErrFilePersisted = errors.New("file is persisted")
)
FileEntry errors.
Functions ¶
func IsFileStateError ¶
IsFileStateError returns true if the param is of FileStateError type.
Types ¶
type Cleanup ¶
type Cleanup struct {
// contains filtered or unexported fields
}
Cleanup contains a list of function that are called to cleanup a fixture
func (*Cleanup) AppendFront ¶
AppendFront append funcs from another cleanup in front of the funcs list
type FileEntry ¶
type FileEntry interface {
GetState() FileState
GetName() string
GetPath() string
GetStat() (os.FileInfo, error)
Create(targetState FileState, len int64) error
Reload() error
MoveFrom(targetState FileState, sourcePath string) error
Move(targetState FileState) error
LinkTo(targetPath string) error
Delete() error
GetReader() (FileReader, error)
GetReadWriter() (FileReadWriter, error)
AddMetadata(md metadata.Metadata) error
GetMetadata(md metadata.Metadata) error
SetMetadata(md metadata.Metadata) (bool, error)
SetMetadataAt(md metadata.Metadata, b []byte, offset int64) (updated bool, err error)
GetOrSetMetadata(md metadata.Metadata) error
DeleteMetadata(md metadata.Metadata) error
RangeMetadata(f func(md metadata.Metadata) error) error
}
FileEntry manages one file and its metadata. It doesn't guarantee thread-safety; That should be handled by FileMap.
type FileEntryFactory ¶
type FileEntryFactory interface {
// Create creates a file entry given a state directory and a name.
// It calls GetRelativePath to generate the actual file path under given directory,
Create(name string, state FileState) FileEntry
// GetRelativePath returns the relative path for a file entry.
// The path is relative to the state directory that file entry belongs to.
// i.e. a file entry can have a relative path of 00/0e/filename under directory /var/cache/
GetRelativePath(name string) string
}
FileEntryFactory initializes FileEntry obj.
func NewCASFileEntryFactory ¶
func NewCASFileEntryFactory() FileEntryFactory
NewCASFileEntryFactory is the constructor for casFileEntryFactory.
func NewLocalFileEntryFactory ¶
func NewLocalFileEntryFactory() FileEntryFactory
NewLocalFileEntryFactory is the constructor for localFileEntryFactory.
type FileMap ¶
type FileMap interface {
Contains(name string) bool
TryStore(name string, entry FileEntry, f func(string, FileEntry) bool) bool
LoadForWrite(name string, f func(string, FileEntry)) bool
LoadForRead(name string, f func(string, FileEntry)) bool
LoadForPeek(name string, f func(string, FileEntry)) bool
Delete(name string, f func(string, FileEntry) bool) bool
}
FileMap is a thread-safe name -> FileEntry map.
func NewLATFileMap ¶
NewLATFileMap creates a new file map that tracks last access time, but no auto-eviction.
type FileOp ¶
type FileOp interface {
AcceptState(state FileState) FileOp
CreateFile(name string, createState FileState, len int64) error
MoveFileFrom(name string, createState FileState, sourcePath string) error
MoveFile(name string, goalState FileState) error
LinkFileTo(name string, targetPath string) error
DeleteFile(name string) error
GetFilePath(name string) (string, error)
GetFileStat(name string) (os.FileInfo, error)
GetFileReader(name string) (FileReader, error)
GetFileReadWriter(name string) (FileReadWriter, error)
GetFileMetadata(name string, md metadata.Metadata) error
SetFileMetadata(name string, md metadata.Metadata) (bool, error)
SetFileMetadataAt(name string, md metadata.Metadata, b []byte, offset int64) (bool, error)
GetOrSetFileMetadata(name string, md metadata.Metadata) error
DeleteFileMetadata(name string, md metadata.Metadata) error
}
FileOp performs one file or metadata operation on FileStore, given a list of acceptable states.
func NewLocalFileOp ¶
func NewLocalFileOp(s *localFileStore) FileOp
NewLocalFileOp inits a new FileOp obj.
type FileReadWriter ¶
type FileReadWriter interface {
FileReader
io.Writer
io.WriterAt
}
FileReadWriter provides read/write operation on a file.
type FileReader ¶
FileReader provides read operation on a file.
type FileState ¶
type FileState struct {
// contains filtered or unexported fields
}
FileState decides what directory a file is in. A file can only be in one state at any given time.
func NewFileState ¶
NewFileState creates a new FileState for directory.
func (FileState) GetDirectory ¶
GetDirectory returns the FileState's directory.
type FileStateError ¶
FileStateError represents errors related to file state. It's used when a file is not in the state it was supposed to be in.
func (*FileStateError) Error ¶
func (e *FileStateError) Error() string
type FileStore ¶
type FileStore interface {
NewFileOp() FileOp
}
FileStore manages files and their metadata. Actual operations are done through FileOp.
func NewCASFileStore ¶
NewCASFileStore initializes and returns a new Content-Addressable FileStore. It uses the first few bytes of file digest (which is also used as file name) as shard ID. For every byte, one more level of directories will be created.
func NewLRUFileStore ¶
NewLRUFileStore initializes and returns a new LRU FileStore. When size exceeds limit, the least recently accessed entry will be removed.
func NewLocalFileStore ¶
NewLocalFileStore initializes and returns a new FileStore.