aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2/filer_structure.go
blob: c78704184d30ebc101454042c766cb6243fac8b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package filer2

import (
	"errors"
	"os"
	"time"
	"path/filepath"
)

type FileId string //file id in SeaweedFS
type FullPath string

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
}

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
	Size   uint64      // total size in bytes
}

type Entry struct {
	FullPath

	Attr

	// the following is for files
	Chunks []FileChunk `json:"chunks,omitempty"`
}

type FileChunk struct {
	Fid    FileId `json:"fid,omitempty"`
	Offset int64  `json:"offset,omitempty"`
	Size   uint64 `json:"size,omitempty"` // size in bytes
}

type AbstractFiler interface {
	CreateEntry(*Entry) (error)
	AppendFileChunk(FullPath, 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, FileChunk) (err error)
	FindEntry(FullPath) (found bool, entry *Entry, err error)
	DeleteEntry(FullPath) (fileEntry *Entry, err error)

	ListDirectoryEntries(dirPath FullPath) ([]*Entry, error)
}