Commit 53e30f5e authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Rename:

* getDataNoCache() -> GetFresh()

* getBranchResult() -> getBranch()

* struct getBranchResult -> branchResult
parent c9b1b570
...@@ -49,7 +49,7 @@ func (me *TimedCache) Get(name string) interface{} { ...@@ -49,7 +49,7 @@ func (me *TimedCache) Get(name string) interface{} {
if ok && info.expiryNs > now { if ok && info.expiryNs > now {
return info.data return info.data
} }
return me.getDataNoCache(name) return me.GetFresh(name)
} }
func (me *TimedCache) Set(name string, val interface{}) { func (me *TimedCache) Set(name string, val interface{}) {
...@@ -69,7 +69,7 @@ func (me *TimedCache) DropEntry(name string) { ...@@ -69,7 +69,7 @@ func (me *TimedCache) DropEntry(name string) {
me.cacheMap[name] = nil, false me.cacheMap[name] = nil, false
} }
func (me *TimedCache) getDataNoCache(name string) interface{} { func (me *TimedCache) GetFresh(name string) interface{} {
data := me.fetch(name) data := me.fetch(name)
me.Set(name, data) me.Set(name, data)
return data return data
......
...@@ -129,23 +129,19 @@ func (me *UnionFs) isDeleted(name string) bool { ...@@ -129,23 +129,19 @@ func (me *UnionFs) isDeleted(name string) bool {
return fi != nil return fi != nil
} }
func (me *UnionFs) getBranchResult(name string) getBranchResult { func (me *UnionFs) getBranch(name string) branchResult {
name = stripSlash(name) name = stripSlash(name)
r := me.branchCache.Get(name) r := me.branchCache.Get(name)
return r.(getBranchResult) return r.(branchResult)
} }
func (me *UnionFs) getBranch(name string) int { type branchResult struct {
return me.getBranchResult(name).branch
}
type getBranchResult struct {
attr *fuse.Attr attr *fuse.Attr
code fuse.Status code fuse.Status
branch int branch int
} }
func (me *UnionFs) getBranchAttrNoCache(name string) getBranchResult { func (me *UnionFs) getBranchAttrNoCache(name string) branchResult {
name = stripSlash(name) name = stripSlash(name)
parent, base := path.Split(name) parent, base := path.Split(name)
...@@ -153,7 +149,7 @@ func (me *UnionFs) getBranchAttrNoCache(name string) getBranchResult { ...@@ -153,7 +149,7 @@ func (me *UnionFs) getBranchAttrNoCache(name string) getBranchResult {
parentBranch := 0 parentBranch := 0
if base != "" { if base != "" {
parentBranch = me.getBranch(parent) parentBranch = me.getBranch(parent).branch
} }
for i, fs := range me.fileSystems { for i, fs := range me.fileSystems {
if i < parentBranch { if i < parentBranch {
...@@ -167,7 +163,7 @@ func (me *UnionFs) getBranchAttrNoCache(name string) getBranchResult { ...@@ -167,7 +163,7 @@ func (me *UnionFs) getBranchAttrNoCache(name string) getBranchResult {
a.Mode |= 0200 a.Mode |= 0200
} }
return getBranchResult{ return branchResult{
attr: a, attr: a,
code: s, code: s,
branch: i, branch: i,
...@@ -178,7 +174,7 @@ func (me *UnionFs) getBranchAttrNoCache(name string) getBranchResult { ...@@ -178,7 +174,7 @@ func (me *UnionFs) getBranchAttrNoCache(name string) getBranchResult {
} }
} }
} }
return getBranchResult{nil, fuse.ENOENT, -1} return branchResult{nil, fuse.ENOENT, -1}
} }
//////////////// ////////////////
...@@ -253,7 +249,7 @@ func CopyFile(dstName, srcName string) (written int64, err os.Error) { ...@@ -253,7 +249,7 @@ func CopyFile(dstName, srcName string) (written int64, err os.Error) {
return io.Copy(dst, src) return io.Copy(dst, src)
} }
func (me *UnionFs) Promote(name string, srcResult getBranchResult) fuse.Status { func (me *UnionFs) Promote(name string, srcResult branchResult) fuse.Status {
writable := me.branches[0] writable := me.branches[0]
sourceFs := me.branches[srcResult.branch] sourceFs := me.branches[srcResult.branch]
...@@ -261,7 +257,7 @@ func (me *UnionFs) Promote(name string, srcResult getBranchResult) fuse.Status { ...@@ -261,7 +257,7 @@ func (me *UnionFs) Promote(name string, srcResult getBranchResult) fuse.Status {
me.promoteDirsTo(name) me.promoteDirsTo(name)
_, err := CopyFile(writable.GetPath(name), sourceFs.GetPath(name)) _, err := CopyFile(writable.GetPath(name), sourceFs.GetPath(name))
r := me.getBranchResult(name) r := me.getBranch(name)
r.branch = 0 r.branch = 0
me.branchCache.Set(name, r) me.branchCache.Set(name, r)
...@@ -277,7 +273,7 @@ func (me *UnionFs) Promote(name string, srcResult getBranchResult) fuse.Status { ...@@ -277,7 +273,7 @@ func (me *UnionFs) Promote(name string, srcResult getBranchResult) fuse.Status {
// Below: implement interface for a FileSystem. // Below: implement interface for a FileSystem.
func (me *UnionFs) Rmdir(path string) (code fuse.Status) { func (me *UnionFs) Rmdir(path string) (code fuse.Status) {
r := me.getBranchResult(path) r := me.getBranch(path)
if r.code != fuse.OK { if r.code != fuse.OK {
return r.code return r.code
} }
...@@ -302,7 +298,7 @@ func (me *UnionFs) Rmdir(path string) (code fuse.Status) { ...@@ -302,7 +298,7 @@ func (me *UnionFs) Rmdir(path string) (code fuse.Status) {
return code return code
} }
r = me.branchCache.getDataNoCache(path).(getBranchResult) r = me.branchCache.GetFresh(path).(branchResult)
if r.branch > 0 { if r.branch > 0 {
code = me.putDeletion(path) code = me.putDeletion(path)
} }
...@@ -310,7 +306,7 @@ func (me *UnionFs) Rmdir(path string) (code fuse.Status) { ...@@ -310,7 +306,7 @@ func (me *UnionFs) Rmdir(path string) (code fuse.Status) {
} }
func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) { func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) {
r := me.getBranchResult(path) r := me.getBranch(path)
if r.code != fuse.ENOENT { if r.code != fuse.ENOENT {
return syscall.EEXIST return syscall.EEXIST
} }
...@@ -320,7 +316,7 @@ func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) { ...@@ -320,7 +316,7 @@ func (me *UnionFs) Mkdir(path string, mode uint32) (code fuse.Status) {
attr := &fuse.Attr{ attr := &fuse.Attr{
Mode: fuse.S_IFDIR | mode, Mode: fuse.S_IFDIR | mode,
} }
me.branchCache.Set(path, getBranchResult{attr, fuse.OK, 0}) me.branchCache.Set(path, branchResult{attr, fuse.OK, 0})
} }
return code return code
} }
...@@ -329,13 +325,13 @@ func (me *UnionFs) Symlink(pointedTo string, linkName string) (code fuse.Status) ...@@ -329,13 +325,13 @@ func (me *UnionFs) Symlink(pointedTo string, linkName string) (code fuse.Status)
code = me.fileSystems[0].Symlink(pointedTo, linkName) code = me.fileSystems[0].Symlink(pointedTo, linkName)
if code == fuse.OK { if code == fuse.OK {
me.removeDeletion(linkName) me.removeDeletion(linkName)
me.branchCache.Set(linkName, getBranchResult{nil, fuse.OK, 0}) me.branchCache.Set(linkName, branchResult{nil, fuse.OK, 0})
} }
return code return code
} }
func (me *UnionFs) Truncate(path string, offset uint64) (code fuse.Status) { func (me *UnionFs) Truncate(path string, offset uint64) (code fuse.Status) {
r := me.getBranchResult(path) r := me.getBranch(path)
if r.branch > 0 { if r.branch > 0 {
code := me.Promote(path, r) code := me.Promote(path, r)
if code != fuse.OK { if code != fuse.OK {
...@@ -348,7 +344,7 @@ func (me *UnionFs) Truncate(path string, offset uint64) (code fuse.Status) { ...@@ -348,7 +344,7 @@ func (me *UnionFs) Truncate(path string, offset uint64) (code fuse.Status) {
func (me *UnionFs) Chmod(name string, mode uint32) (code fuse.Status) { func (me *UnionFs) Chmod(name string, mode uint32) (code fuse.Status) {
name = stripSlash(name) name = stripSlash(name)
r := me.getBranchResult(name) r := me.getBranch(name)
if r.attr == nil { if r.attr == nil {
return r.code return r.code
} }
...@@ -378,26 +374,25 @@ func (me *UnionFs) Chmod(name string, mode uint32) (code fuse.Status) { ...@@ -378,26 +374,25 @@ func (me *UnionFs) Chmod(name string, mode uint32) (code fuse.Status) {
} }
func (me *UnionFs) Access(name string, mode uint32) (code fuse.Status) { func (me *UnionFs) Access(name string, mode uint32) (code fuse.Status) {
i := me.getBranch(name) r := me.getBranch(name)
if i >= 0 { if r.branch >= 0 {
return me.fileSystems[i].Access(name, mode) return me.fileSystems[r.branch].Access(name, mode)
} }
return fuse.ENOENT return fuse.ENOENT
} }
func (me *UnionFs) Unlink(name string) (code fuse.Status) { func (me *UnionFs) Unlink(name string) (code fuse.Status) {
branch := me.getBranch(name) r := me.getBranch(name)
if branch == 0 { if r.branch == 0 {
code = me.fileSystems[0].Unlink(name) code = me.fileSystems[0].Unlink(name)
if code != fuse.OK { if code != fuse.OK {
return code return code
} }
r := me.branchCache.getDataNoCache(name) r = me.branchCache.GetFresh(name).(branchResult)
branch = r.(getBranchResult).branch
} }
if branch > 0 { if r.branch > 0 {
// It would be nice to do the putDeletion async. // It would be nice to do the putDeletion async.
code = me.putDeletion(name) code = me.putDeletion(name)
} }
...@@ -405,9 +400,9 @@ func (me *UnionFs) Unlink(name string) (code fuse.Status) { ...@@ -405,9 +400,9 @@ func (me *UnionFs) Unlink(name string) (code fuse.Status) {
} }
func (me *UnionFs) Readlink(name string) (out string, code fuse.Status) { func (me *UnionFs) Readlink(name string) (out string, code fuse.Status) {
i := me.getBranch(name) r := me.getBranch(name)
if i >= 0 { if r.branch >= 0 {
return me.fileSystems[i].Readlink(name) return me.fileSystems[r.branch].Readlink(name)
} }
return "", fuse.ENOENT return "", fuse.ENOENT
} }
...@@ -426,9 +421,9 @@ func (me *UnionFs) promoteDirsTo(filename string) fuse.Status { ...@@ -426,9 +421,9 @@ func (me *UnionFs) promoteDirsTo(filename string) fuse.Status {
dirName = stripSlash(dirName) dirName = stripSlash(dirName)
var todo []string var todo []string
var results []getBranchResult var results []branchResult
for dirName != "" { for dirName != "" {
r := me.getBranchResult(dirName) r := me.getBranch(dirName)
if r.code != fuse.OK { if r.code != fuse.OK {
log.Println("path component does not exist", filename, dirName) log.Println("path component does not exist", filename, dirName)
...@@ -476,7 +471,7 @@ func (me *UnionFs) Create(name string, flags uint32, mode uint32) (fuseFile fuse ...@@ -476,7 +471,7 @@ func (me *UnionFs) Create(name string, flags uint32, mode uint32) (fuseFile fuse
a := fuse.Attr{ a := fuse.Attr{
Mode: fuse.S_IFREG | mode, Mode: fuse.S_IFREG | mode,
} }
me.branchCache.Set(name, getBranchResult{&a, fuse.OK, 0}) me.branchCache.Set(name, branchResult{&a, fuse.OK, 0})
} }
return fuseFile, code return fuseFile, code
} }
...@@ -497,7 +492,7 @@ func (me *UnionFs) GetAttr(name string) (a *fuse.Attr, s fuse.Status) { ...@@ -497,7 +492,7 @@ func (me *UnionFs) GetAttr(name string) (a *fuse.Attr, s fuse.Status) {
if me.isDeleted(name) { if me.isDeleted(name) {
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
r := me.getBranchResult(name) r := me.getBranch(name)
if r.branch < 0 { if r.branch < 0 {
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
...@@ -508,16 +503,16 @@ func (me *UnionFs) GetAttr(name string) (a *fuse.Attr, s fuse.Status) { ...@@ -508,16 +503,16 @@ func (me *UnionFs) GetAttr(name string) (a *fuse.Attr, s fuse.Status) {
} }
func (me *UnionFs) GetXAttr(name string, attr string) ([]byte, fuse.Status) { func (me *UnionFs) GetXAttr(name string, attr string) ([]byte, fuse.Status) {
branch := me.getBranch(name) r := me.getBranch(name)
if branch >= 0 { if r.branch >= 0 {
return me.fileSystems[branch].GetXAttr(name, attr) return me.fileSystems[r.branch].GetXAttr(name, attr)
} }
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
func (me *UnionFs) OpenDir(directory string) (stream chan fuse.DirEntry, status fuse.Status) { func (me *UnionFs) OpenDir(directory string) (stream chan fuse.DirEntry, status fuse.Status) {
dirBranch := me.getBranch(directory) dirBranch := me.getBranch(directory)
if dirBranch < 0 { if dirBranch.branch < 0 {
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
...@@ -538,7 +533,7 @@ func (me *UnionFs) OpenDir(directory string) (stream chan fuse.DirEntry, status ...@@ -538,7 +533,7 @@ func (me *UnionFs) OpenDir(directory string) (stream chan fuse.DirEntry, status
statuses := make([]fuse.Status, len(me.branches)) statuses := make([]fuse.Status, len(me.branches))
var wg sync.WaitGroup var wg sync.WaitGroup
for i, l := range me.fileSystems { for i, l := range me.fileSystems {
if i >= dirBranch { if i >= dirBranch.branch {
wg.Add(1) wg.Add(1)
go func(j int, pfs fuse.FileSystem) { go func(j int, pfs fuse.FileSystem) {
ch, s := pfs.OpenDir(directory) ch, s := pfs.OpenDir(directory)
...@@ -603,7 +598,7 @@ func (me *UnionFs) OpenDir(directory string) (stream chan fuse.DirEntry, status ...@@ -603,7 +598,7 @@ func (me *UnionFs) OpenDir(directory string) (stream chan fuse.DirEntry, status
} }
func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) { func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) {
srcResult := me.getBranchResult(src) srcResult := me.getBranch(src)
if srcResult.code != fuse.OK { if srcResult.code != fuse.OK {
return srcResult.code return srcResult.code
} }
...@@ -624,8 +619,8 @@ func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) { ...@@ -624,8 +619,8 @@ func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) {
me.branchCache.Set(dst, srcResult) me.branchCache.Set(dst, srcResult)
if srcResult.branch == 0 { if srcResult.branch == 0 {
srcResult := me.branchCache.getDataNoCache(src) srcResult := me.branchCache.GetFresh(src)
if srcResult.(getBranchResult).branch > 0 { if srcResult.(branchResult).branch > 0 {
code = me.putDeletion(src) code = me.putDeletion(src)
} }
} else { } else {
...@@ -636,7 +631,7 @@ func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) { ...@@ -636,7 +631,7 @@ func (me *UnionFs) Rename(src string, dst string) (status fuse.Status) {
} }
func (me *UnionFs) Open(name string, flags uint32) (fuseFile fuse.File, status fuse.Status) { func (me *UnionFs) Open(name string, flags uint32) (fuseFile fuse.File, status fuse.Status) {
r := me.getBranchResult(name) r := me.getBranch(name)
branch := r.branch branch := r.branch
if flags&fuse.O_ANYWRITE != 0 && r.branch > 0 { if flags&fuse.O_ANYWRITE != 0 && r.branch > 0 {
code := me.Promote(name, r) code := me.Promote(name, r)
...@@ -651,7 +646,7 @@ func (me *UnionFs) Open(name string, flags uint32) (fuseFile fuse.File, status f ...@@ -651,7 +646,7 @@ func (me *UnionFs) Open(name string, flags uint32) (fuseFile fuse.File, status f
func (me *UnionFs) Release(name string) { func (me *UnionFs) Release(name string) {
me.branchCache.DropEntry(name) me.branchCache.DropEntry(name)
// Refresh to pick up the new size. // Refresh to pick up the new size.
me.getBranchResult(name) me.getBranch(name)
} }
func (me *UnionFs) Roots() (result []string) { func (me *UnionFs) Roots() (result []string) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment