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

49
dir.go
View File

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

10
file.go
View File

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

18
node.go
View File

@ -23,10 +23,11 @@
package main package main
import ( import (
"bazil.org/fuse"
"os" "os"
"syscall" "syscall"
"time" "time"
"bazil.org/fuse"
) )
// //
@ -91,21 +92,6 @@ func (this *versionedNode) setAttr(req *fuse.SetattrRequest, resp *fuse.SetattrR
return nil 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 { func (this *versionedNode) rebasedPath() string {
return this.ver.rebasePath(this.path) return this.ver.rebasePath(this.path)
} }