2018-05-11 09:20:15 +00:00
|
|
|
package filer2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"time"
|
2018-05-12 20:45:29 +00:00
|
|
|
"path/filepath"
|
2018-05-16 07:08:44 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2018-05-21 08:25:30 +00:00
|
|
|
"strings"
|
2018-05-11 09:20:15 +00:00
|
|
|
)
|
|
|
|
|
2018-05-12 20:45:29 +00:00
|
|
|
type FullPath string
|
|
|
|
|
2018-05-14 09:02:17 +00:00
|
|
|
func NewFullPath(dir, name string) FullPath {
|
2018-05-21 08:25:30 +00:00
|
|
|
if strings.HasSuffix(dir, "/") {
|
2018-05-14 09:02:17 +00:00
|
|
|
return FullPath(dir + name)
|
|
|
|
}
|
|
|
|
return FullPath(dir + "/" + name)
|
|
|
|
}
|
|
|
|
|
2018-05-12 20:45:29 +00:00
|
|
|
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
|
2018-05-11 09:20:15 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 06:56:16 +00:00
|
|
|
func (fp FullPath) Name() (string) {
|
|
|
|
_, name := filepath.Split(string(fp))
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2018-05-11 09:20:15 +00:00
|
|
|
type Attr struct {
|
2018-05-12 20:45:29 +00:00
|
|
|
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
|
2018-05-11 09:20:15 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 06:56:16 +00:00
|
|
|
func (attr Attr) IsDirectory() (bool) {
|
2018-05-14 09:02:17 +00:00
|
|
|
return attr.Mode&os.ModeDir > 0
|
2018-05-14 06:56:16 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 09:20:15 +00:00
|
|
|
type Entry struct {
|
2018-05-12 20:45:29 +00:00
|
|
|
FullPath
|
2018-05-11 09:20:15 +00:00
|
|
|
|
|
|
|
Attr
|
|
|
|
|
|
|
|
// the following is for files
|
2018-05-16 07:08:44 +00:00
|
|
|
Chunks []*filer_pb.FileChunk `json:"chunks,omitempty"`
|
2018-05-11 09:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AbstractFiler interface {
|
2018-05-12 20:45:29 +00:00
|
|
|
CreateEntry(*Entry) (error)
|
2018-05-16 07:08:44 +00:00
|
|
|
AppendFileChunk(FullPath, []*filer_pb.FileChunk) (err error)
|
2018-05-12 20:45:29 +00:00
|
|
|
FindEntry(FullPath) (found bool, fileEntry *Entry, err error)
|
|
|
|
DeleteEntry(FullPath) (fileEntry *Entry, err error)
|
2018-05-11 09:20:15 +00:00
|
|
|
|
2018-05-12 20:45:29 +00:00
|
|
|
ListDirectoryEntries(dirPath FullPath) ([]*Entry, error)
|
|
|
|
UpdateEntry(*Entry) (error)
|
2018-05-11 09:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var ErrNotFound = errors.New("filer: no entry is found in filer store")
|
|
|
|
|
|
|
|
type FilerStore interface {
|
2018-05-12 20:45:29 +00:00
|
|
|
InsertEntry(*Entry) (error)
|
2018-05-22 10:26:38 +00:00
|
|
|
UpdateEntry(*Entry) (err error)
|
2018-05-12 20:45:29 +00:00
|
|
|
FindEntry(FullPath) (found bool, entry *Entry, err error)
|
|
|
|
DeleteEntry(FullPath) (fileEntry *Entry, err error)
|
2018-05-11 09:20:15 +00:00
|
|
|
|
2018-05-13 21:02:29 +00:00
|
|
|
ListDirectoryEntries(dirPath FullPath, startFileName string, inclusive bool, limit int) ([]*Entry, error)
|
2018-05-11 09:20:15 +00:00
|
|
|
}
|