Work in progress

This commit is contained in:
Alex Yatskov 2015-06-17 20:11:16 +09:00
parent ff9a014afc
commit 48faaa74f4
4 changed files with 49 additions and 30 deletions

43
dir.go
View File

@ -23,12 +23,13 @@
package main
import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"errors"
"golang.org/x/net/context"
"os"
"path"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)
//
@ -61,7 +62,9 @@ func (this *versionedDir) version() error {
return err
}
node.ver.meta.modifyNode(node.path)
this.node = node
return nil
}
@ -79,6 +82,7 @@ func (this *versionedDir) createDir(name string) (*versionedDir, error) {
dir := newVersionedDir(node, this)
this.dirs[name] = dir
node.ver.meta.createNode(node.path)
return dir, nil
}
@ -98,6 +102,7 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er
file.handle = handle
this.files[name] = file
node.ver.meta.createNode(node.path)
return file, nil
}
@ -143,18 +148,38 @@ func (this *versionedDir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs
return this.createDir(req.Name)
}
func (this *versionedDir) Remove(ctx context.Context, req *fuse.RemoveRequest) (err error) {
func (this *versionedDir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
if req.Dir {
if err = this.dirs[req.Name].node.remove(); err == nil {
delete(this.dirs, req.Name)
node := this.dirs[req.Name].node
ver := node.ver
if node.flags&NodeFlagVer == NodeFlagVer {
if err := os.Remove(node.rebasedPath()); err != nil {
return err
}
ver = ver.parent
}
ver.meta.removeNode(node.path)
delete(this.dirs, req.Name)
} else {
if err = this.files[req.Name].node.remove(); err == nil {
delete(this.files, req.Name)
node := this.files[req.Name].node
ver := node.ver
if node.flags&NodeFlagVer == NodeFlagVer {
if err := os.Remove(node.rebasedPath()); err != nil {
return err
}
ver = ver.parent
}
ver.meta.removeNode(node.path)
delete(this.files, req.Name)
}
return
return nil
}
func (this *versionedDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {

10
file.go
View File

@ -23,12 +23,13 @@
package main
import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"errors"
"golang.org/x/net/context"
"io"
"os"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)
//
@ -57,7 +58,9 @@ func (this *versionedFile) version() error {
return err
}
node.ver.meta.modifyNode(node.path)
this.node = node
return nil
}
@ -147,6 +150,7 @@ func (this *versionedFile) Release(ctx context.Context, req *fuse.ReleaseRequest
this.handle.Close()
this.handle = nil
return nil
}

View File

@ -58,12 +58,16 @@ func (this *versionMetadata) filter(nodes versionedNodeMap) {
}
}
func (this *versionMetadata) destroyPath(path string) {
func (this *versionMetadata) removeNode(path string) {
this.Deleted = append(this.Deleted, path)
this.dirty = true
}
func (this *versionMetadata) createPath(path string) {
func (this *versionMetadata) createNode(path string) {
this.dirty = true
}
func (this *versionMetadata) modifyNode(path string) {
this.dirty = true
}

18
node.go
View File

@ -23,10 +23,11 @@
package main
import (
"bazil.org/fuse"
"os"
"syscall"
"time"
"bazil.org/fuse"
)
//
@ -91,21 +92,6 @@ func (this *versionedNode) setAttr(req *fuse.SetattrRequest, resp *fuse.SetattrR
return nil
}
func (this *versionedNode) remove() error {
ver := this.ver
if this.flags&NodeFlagVer == NodeFlagVer {
if err := os.Remove(this.rebasedPath()); err != nil {
return err
}
ver = ver.parent
}
ver.meta.destroyPath(this.path)
return nil
}
func (this *versionedNode) rebasedPath() string {
return this.ver.rebasePath(this.path)
}