Work in progress
This commit is contained in:
parent
4404362eb9
commit
1b44c1e1a6
@ -103,10 +103,6 @@ func (this *database) buildVersions(base string) ([]*version, error) {
|
|||||||
prev = ver
|
prev = ver
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ver := range vers {
|
|
||||||
ver.last = vers[len(vers)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
return vers, nil
|
return vers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
dir.go
9
dir.go
@ -58,7 +58,7 @@ func (this *versionedDir) createDir(name string) (*versionedDir, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
node, err := newVersionedNode(childPath, this.node.ver)
|
node, err := newVersionedNode(childPath, this.node.ver, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
node, err := newVersionedNode(childPath, this.node.ver)
|
node, err := newVersionedNode(childPath, this.node.ver, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -89,9 +89,10 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er
|
|||||||
return file, nil
|
return file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *versionedDir) Attr(attr *fuse.Attr) {
|
func (this *versionedDir) Attr(ctx context.Context, attr *fuse.Attr) error {
|
||||||
this.node.attr(attr)
|
this.node.attr(attr)
|
||||||
attr.Inode = this.inode
|
attr.Inode = this.inode
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *versionedDir) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error {
|
func (this *versionedDir) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error {
|
||||||
@ -99,7 +100,7 @@ func (this *versionedDir) Getattr(ctx context.Context, req *fuse.GetattrRequest,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Attr(&resp.Attr)
|
this.Attr(ctx, &resp.Attr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
file.go
5
file.go
@ -62,9 +62,10 @@ func (this *versionedFile) Open(ctx context.Context, req *fuse.OpenRequest, resp
|
|||||||
return this, nil
|
return this, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *versionedFile) Attr(attr *fuse.Attr) {
|
func (this *versionedFile) Attr(ctx context.Context, attr *fuse.Attr) error {
|
||||||
this.node.attr(attr)
|
this.node.attr(attr)
|
||||||
attr.Inode = this.inode
|
attr.Inode = this.inode
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *versionedFile) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error {
|
func (this *versionedFile) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error {
|
||||||
@ -72,7 +73,7 @@ func (this *versionedFile) Getattr(ctx context.Context, req *fuse.GetattrRequest
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Attr(&resp.Attr)
|
this.Attr(ctx, &resp.Attr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
node.go
17
node.go
@ -37,21 +37,22 @@ type versionedNode struct {
|
|||||||
path string
|
path string
|
||||||
info os.FileInfo
|
info os.FileInfo
|
||||||
ver *version
|
ver *version
|
||||||
|
parent *versionedNode
|
||||||
}
|
}
|
||||||
|
|
||||||
type versionedNodeMap map[string]*versionedNode
|
type versionedNodeMap map[string]*versionedNode
|
||||||
|
|
||||||
func newVersionedNode(path string, ver *version) (*versionedNode, error) {
|
func newVersionedNode(path string, ver *version, parent *versionedNode) (*versionedNode, error) {
|
||||||
info, err := os.Stat(ver.rebasePath(path))
|
info, err := os.Stat(ver.rebasePath(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return newVersionedNodeStat(path, ver, info), nil
|
return newVersionedNodeStat(path, ver, parent, info), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newVersionedNodeStat(path string, ver *version, info os.FileInfo) *versionedNode {
|
func newVersionedNodeStat(path string, ver *version, parent *versionedNode, info os.FileInfo) *versionedNode {
|
||||||
return &versionedNode{path, info, ver}
|
return &versionedNode{path, info, ver, parent}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *versionedNode) setAttr(req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
|
func (this *versionedNode) setAttr(req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
|
||||||
@ -111,14 +112,6 @@ func (this *versionedNode) rebasedPath() string {
|
|||||||
return this.ver.rebasePath(this.path)
|
return this.ver.rebasePath(this.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *versionedNode) rebasedTermPath() string {
|
|
||||||
if this.ver.last == nil {
|
|
||||||
return this.rebasedPath()
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.ver.last.rebasePath(this.path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *versionedNode) owner() (gid, uid uint32) {
|
func (this *versionedNode) owner() (gid, uid uint32) {
|
||||||
stat := this.info.Sys().(*syscall.Stat_t)
|
stat := this.info.Sys().(*syscall.Stat_t)
|
||||||
|
|
||||||
|
16
version.go
16
version.go
@ -42,14 +42,13 @@ import (
|
|||||||
|
|
||||||
type version struct {
|
type version struct {
|
||||||
base string
|
base string
|
||||||
prev *version
|
parent *version
|
||||||
last *version
|
|
||||||
timestamp time.Time
|
timestamp time.Time
|
||||||
meta *versionMetadata
|
meta *versionMetadata
|
||||||
root *versionedDir
|
root *versionedDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func newVersion(base string, timestamp time.Time, prev *version) (*version, error) {
|
func newVersion(base string, timestamp time.Time, parent *version) (*version, error) {
|
||||||
meta, err := newVersionMetadata(filepath.Join(base, "meta.json"))
|
meta, err := newVersionMetadata(filepath.Join(base, "meta.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -57,7 +56,7 @@ func newVersion(base string, timestamp time.Time, prev *version) (*version, erro
|
|||||||
|
|
||||||
ver := &version{
|
ver := &version{
|
||||||
base: base,
|
base: base,
|
||||||
prev: prev,
|
parent: parent,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
meta: meta}
|
meta: meta}
|
||||||
|
|
||||||
@ -66,10 +65,10 @@ func newVersion(base string, timestamp time.Time, prev *version) (*version, erro
|
|||||||
|
|
||||||
func (this *version) scanNode(node *versionedNode) (versionedNodeMap, error) {
|
func (this *version) scanNode(node *versionedNode) (versionedNodeMap, error) {
|
||||||
var baseNodes versionedNodeMap
|
var baseNodes versionedNodeMap
|
||||||
if this.prev != nil {
|
if this.parent != nil {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
baseNodes, err = this.prev.scanNode(node)
|
baseNodes, err = this.parent.scanNode(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -88,7 +87,7 @@ func (this *version) scanNode(node *versionedNode) (versionedNodeMap, error) {
|
|||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
childName := info.Name()
|
childName := info.Name()
|
||||||
childPath := filepath.Join(node.path, childName)
|
childPath := filepath.Join(node.path, childName)
|
||||||
ownNodes[childName] = newVersionedNodeStat(childPath, this, info)
|
ownNodes[childName] = newVersionedNodeStat(childPath, this, nil, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +99,7 @@ func (this *version) scanNode(node *versionedNode) (versionedNodeMap, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ownName, ownNode := range ownNodes {
|
for ownName, ownNode := range ownNodes {
|
||||||
|
ownNode.parent, _ = baseNodes[ownName]
|
||||||
baseNodes[ownName] = ownNode
|
baseNodes[ownName] = ownNode
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ func (this *version) buildVerDir(dir *versionedDir) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *version) resolve() error {
|
func (this *version) resolve() error {
|
||||||
node, err := newVersionedNode("/", this)
|
node, err := newVersionedNode("/", this, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user