Commit b7c768d4 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

unionfs: use early return for more idiomatic code in Rename()

parent 33c1cab5
...@@ -885,38 +885,38 @@ func (fs *unionFS) renameDirectory(srcResult branchResult, srcDir string, dstDir ...@@ -885,38 +885,38 @@ func (fs *unionFS) renameDirectory(srcResult branchResult, srcDir string, dstDir
return code return code
} }
func (fs *unionFS) Rename(src string, dst string, context *fuse.Context) (code fuse.Status) { func (fs *unionFS) Rename(src string, dst string, context *fuse.Context) fuse.Status {
srcResult := fs.getBranch(src) srcResult := fs.getBranch(src)
code = srcResult.code if !srcResult.code.Ok() {
if code.Ok() { return srcResult.code
code = srcResult.code
} }
if srcResult.attr.IsDir() { if srcResult.attr.IsDir() {
return fs.renameDirectory(srcResult, src, dst, context) return fs.renameDirectory(srcResult, src, dst, context)
} }
if code.Ok() && srcResult.branch > 0 { if srcResult.branch > 0 {
code = fs.Promote(src, srcResult, context) if code := fs.Promote(src, srcResult, context); !code.Ok() {
return code
} }
if code.Ok() {
code = fs.promoteDirsTo(dst)
} }
if code.Ok() { if code := fs.promoteDirsTo(dst); !code.Ok() {
code = fs.fileSystems[0].Rename(src, dst, context) return code
}
if code := fs.fileSystems[0].Rename(src, dst, context); !code.Ok() {
return code
} }
if code.Ok() {
fs.removeDeletion(dst) fs.removeDeletion(dst)
// Rename is racy; avoid racing with unionFsFile.Release(). // Rename is racy; avoid racing with unionFsFile.Release().
fs.branchCache.DropEntry(dst) fs.branchCache.DropEntry(dst)
srcResult := fs.branchCache.GetFresh(src) srcResult = fs.branchCache.GetFresh(src).(branchResult)
if srcResult.(branchResult).branch > 0 { if srcResult.branch > 0 {
code = fs.putDeletion(src) return fs.putDeletion(src)
}
} }
return code return fuse.OK
} }
func (fs *unionFS) DropBranchCache(names []string) { func (fs *unionFS) DropBranchCache(names []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