seaweedfs/weed/filer2/filer_structure.go
Chris Lu b303a02461 cp file can work
1. consolidate to filer_pb.FileChunk
2. dir add file, mkdir
3. file flush, write

updates having issue
2018-05-16 00:08:44 -07:00

77 lines
1.7 KiB
Go

package filer2
import (
"errors"
"os"
"time"
"path/filepath"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
type FullPath string
func NewFullPath(dir, name string) FullPath {
if dir == "/" {
return FullPath(dir + name)
}
return FullPath(dir + "/" + name)
}
func (fp FullPath) DirAndName() (string, string) {
dir, name := filepath.Split(string(fp))
if dir == "/" {
return dir, name
}
if len(dir) < 1 {
return "/", ""
}
return dir[:len(dir)-1], name
}
func (fp FullPath) Name() (string) {
_, name := filepath.Split(string(fp))
return name
}
type Attr struct {
Mtime time.Time // time of last modification
Crtime time.Time // time of creation (OS X only)
Mode os.FileMode // file mode
Uid uint32 // owner uid
Gid uint32 // group gid
}
func (attr Attr) IsDirectory() (bool) {
return attr.Mode&os.ModeDir > 0
}
type Entry struct {
FullPath
Attr
// the following is for files
Chunks []*filer_pb.FileChunk `json:"chunks,omitempty"`
}
type AbstractFiler interface {
CreateEntry(*Entry) (error)
AppendFileChunk(FullPath, []*filer_pb.FileChunk) (err error)
FindEntry(FullPath) (found bool, fileEntry *Entry, err error)
DeleteEntry(FullPath) (fileEntry *Entry, err error)
ListDirectoryEntries(dirPath FullPath) ([]*Entry, error)
UpdateEntry(*Entry) (error)
}
var ErrNotFound = errors.New("filer: no entry is found in filer store")
type FilerStore interface {
InsertEntry(*Entry) (error)
AppendFileChunk(FullPath, []*filer_pb.FileChunk) (err error)
FindEntry(FullPath) (found bool, entry *Entry, err error)
DeleteEntry(FullPath) (fileEntry *Entry, err error)
ListDirectoryEntries(dirPath FullPath, startFileName string, inclusive bool, limit int) ([]*Entry, error)
}