Deleting and creating of directories and files now works correctly.

This commit is contained in:
Alex Yatskov 2015-05-24 18:21:10 +09:00
parent 772019c4a2
commit 4dca3c16f8

27
dir.go
View File

@ -61,18 +61,21 @@ func (this *versionedDir) createDir(name string) (*versionedDir, error) {
} }
node := &versionedNode{childPath, info, this.node.ver} node := &versionedNode{childPath, info, this.node.ver}
return newVersionedDir(node, this.node.ver.inodeAloc.AllocInode(), this), nil dir := newVersionedDir(node, this.node.ver.inodeAloc.AllocInode(), this)
this.dirs[name] = dir
return dir, nil
} }
func (this *versionedDir) createFile(name string, flags int) (*versionedFile, error) { func (this *versionedDir) createFile(name string, flags int) (*versionedFile, error) {
childPath := path.Join(this.node.path, name) childPath := path.Join(this.node.path, name)
childPathFull := this.node.ver.rebasePath(childPath) childPathFull := this.node.ver.rebasePath(childPath)
file, err := os.OpenFile(childPathFull, flags, 0644) handle, err := os.OpenFile(childPathFull, flags, 0644)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer file.Close() defer handle.Close()
info, err := os.Stat(childPathFull) info, err := os.Stat(childPathFull)
if err != nil { if err != nil {
@ -80,7 +83,10 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er
} }
node := &versionedNode{childPath, info, this.node.ver} node := &versionedNode{childPath, info, this.node.ver}
return newVersionedFile(node, this.node.ver.inodeAloc.AllocInode(), this), nil file := newVersionedFile(node, this.node.ver.inodeAloc.AllocInode(), this)
this.files[name] = file
return file, nil
} }
func (this *versionedDir) Attr(attr *fuse.Attr) { func (this *versionedDir) Attr(attr *fuse.Attr) {
@ -106,6 +112,19 @@ func (this *versionedDir) Create(ctx context.Context, req *fuse.CreateRequest, r
} }
} }
func (this *versionedDir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
var fullPath string
if req.Dir {
fullPath = this.dirs[req.Name].node.rebasedPath()
delete(this.dirs, req.Name)
} else {
fullPath = this.files[req.Name].node.rebasedPath()
delete(this.files, req.Name)
}
return os.Remove(fullPath)
}
func (this *versionedDir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) { func (this *versionedDir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) {
return this.createDir(req.Name) return this.createDir(req.Name)
} }