Commit 9da364b3 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Run gofmt.

parent 5ae334dd
...@@ -36,7 +36,7 @@ type FsNode interface { ...@@ -36,7 +36,7 @@ type FsNode interface {
// other inodes. // other inodes.
Deletable() bool Deletable() bool
OnForget() OnForget()
// Misc. // Misc.
Access(mode uint32, context *Context) (code Status) Access(mode uint32, context *Context) (code Status)
Readlink(c *Context) ([]byte, Status) Readlink(c *Context) ([]byte, Status)
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
var _ = log.Println var _ = log.Println
type DefaultNodeFileSystem struct { type DefaultNodeFileSystem struct {
} }
func (me *DefaultNodeFileSystem) OnUnmount() { func (me *DefaultNodeFileSystem) OnUnmount() {
...@@ -102,7 +103,7 @@ func (me *DefaultFsNode) OpenDir(context *Context) (chan DirEntry, Status) { ...@@ -102,7 +103,7 @@ func (me *DefaultFsNode) OpenDir(context *Context) (chan DirEntry, Status) {
ch := me.Inode().Children() ch := me.Inode().Children()
s := make(chan DirEntry, len(ch)) s := make(chan DirEntry, len(ch))
for name, child := range ch { for name, child := range ch {
fi, code := child.FsNode().GetAttr(nil, context) fi, code := child.FsNode().GetAttr(nil, context)
if code.Ok() { if code.Ok() {
s <- DirEntry{Name: name, Mode: fi.Mode} s <- DirEntry{Name: name, Mode: fi.Mode}
} }
......
...@@ -337,4 +337,3 @@ func (me *FileSystemConnector) Flush(header *InHeader, input *FlushIn) Status { ...@@ -337,4 +337,3 @@ func (me *FileSystemConnector) Flush(header *InHeader, input *FlushIn) Status {
opened := node.mount.getOpenedFile(input.Fh) opened := node.mount.getOpenedFile(input.Fh)
return opened.WithFlags.File.Flush() return opened.WithFlags.File.Flush()
} }
...@@ -72,7 +72,7 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -72,7 +72,7 @@ func NewTestCase(t *testing.T) *testCase {
var rfs RawFileSystem var rfs RawFileSystem
me.pathFs = NewPathNodeFs(pfs, &PathNodeFsOptions{ me.pathFs = NewPathNodeFs(pfs, &PathNodeFsOptions{
ClientInodes: true}) ClientInodes: true})
me.connector = NewFileSystemConnector(me.pathFs, me.connector = NewFileSystemConnector(me.pathFs,
&FileSystemOptions{ &FileSystemOptions{
EntryTimeout: testTtl, EntryTimeout: testTtl,
......
...@@ -13,9 +13,9 @@ var _ = log.Println ...@@ -13,9 +13,9 @@ var _ = log.Println
type MemNodeFs struct { type MemNodeFs struct {
DefaultNodeFileSystem DefaultNodeFileSystem
backingStore string backingStore string
root *memNode root *memNode
mutex sync.Mutex mutex sync.Mutex
nextFree int nextFree int
} }
...@@ -53,10 +53,10 @@ func (me *MemNodeFs) Filename(n *Inode) string { ...@@ -53,10 +53,10 @@ func (me *MemNodeFs) Filename(n *Inode) string {
type memNode struct { type memNode struct {
DefaultFsNode DefaultFsNode
fs *MemNodeFs fs *MemNodeFs
id int id int
link string link string
info os.FileInfo info os.FileInfo
} }
func (me *memNode) newNode(isdir bool) *memNode { func (me *memNode) newNode(isdir bool) *memNode {
...@@ -88,7 +88,6 @@ func (me *memNode) Unlink(name string, context *Context) (code Status) { ...@@ -88,7 +88,6 @@ func (me *memNode) Unlink(name string, context *Context) (code Status) {
return OK return OK
} }
func (me *memNode) Rmdir(name string, context *Context) (code Status) { func (me *memNode) Rmdir(name string, context *Context) (code Status) {
return me.Unlink(name, context) return me.Unlink(name, context)
} }
...@@ -98,7 +97,7 @@ func (me *memNode) Symlink(name string, content string, context *Context) (fi *o ...@@ -98,7 +97,7 @@ func (me *memNode) Symlink(name string, content string, context *Context) (fi *o
n.info.Mode = S_IFLNK | 0777 n.info.Mode = S_IFLNK | 0777
n.link = content n.link = content
me.Inode().AddChild(name, n.Inode()) me.Inode().AddChild(name, n.Inode())
return &n.info, n, OK return &n.info, n, OK
} }
...@@ -118,7 +117,7 @@ func (me *memNode) Link(name string, existing FsNode, context *Context) (fi *os. ...@@ -118,7 +117,7 @@ func (me *memNode) Link(name string, existing FsNode, context *Context) (fi *os.
func (me *memNode) Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *os.FileInfo, newNode FsNode, code Status) { func (me *memNode) Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *os.FileInfo, newNode FsNode, code Status) {
n := me.newNode(false) n := me.newNode(false)
n.info.Mode = mode | S_IFREG n.info.Mode = mode | S_IFREG
f, err := os.Create(n.filename()) f, err := os.Create(n.filename())
if err != nil { if err != nil {
return nil, nil, nil, OsErrorToErrno(err) return nil, nil, nil, OsErrorToErrno(err)
...@@ -147,7 +146,7 @@ func (me *memNodeFile) Flush() Status { ...@@ -147,7 +146,7 @@ func (me *memNodeFile) Flush() Status {
func (me *memNode) newFile(f *os.File) File { func (me *memNode) newFile(f *os.File) File {
return &memNodeFile{ return &memNodeFile{
LoopbackFile: LoopbackFile{File: f}, LoopbackFile: LoopbackFile{File: f},
node: me, node: me,
} }
} }
...@@ -160,7 +159,6 @@ func (me *memNode) Open(flags uint32, context *Context) (file File, code Status) ...@@ -160,7 +159,6 @@ func (me *memNode) Open(flags uint32, context *Context) (file File, code Status)
return me.newFile(f), OK return me.newFile(f), OK
} }
func (me *memNode) GetAttr(file File, context *Context) (fi *os.FileInfo, code Status) { func (me *memNode) GetAttr(file File, context *Context) (fi *os.FileInfo, code Status) {
return &me.info, OK return &me.info, OK
} }
...@@ -195,6 +193,3 @@ func (me *memNode) Chown(file File, uid uint32, gid uint32, context *Context) (c ...@@ -195,6 +193,3 @@ func (me *memNode) Chown(file File, uid uint32, gid uint32, context *Context) (c
me.info.Ctime_ns = time.Nanoseconds() me.info.Ctime_ns = time.Nanoseconds()
return OK return OK
} }
...@@ -17,7 +17,7 @@ func setupMemNodeTest(t *testing.T) (wd string, fs *MemNodeFs, clean func()) { ...@@ -17,7 +17,7 @@ func setupMemNodeTest(t *testing.T) (wd string, fs *MemNodeFs, clean func()) {
fs = NewMemNodeFs(back) fs = NewMemNodeFs(back)
mnt := tmp + "/mnt" mnt := tmp + "/mnt"
os.Mkdir(mnt, 0700) os.Mkdir(mnt, 0700)
connector := NewFileSystemConnector(fs, connector := NewFileSystemConnector(fs,
&FileSystemOptions{ &FileSystemOptions{
EntryTimeout: testTtl, EntryTimeout: testTtl,
...@@ -37,14 +37,14 @@ func setupMemNodeTest(t *testing.T) (wd string, fs *MemNodeFs, clean func()) { ...@@ -37,14 +37,14 @@ func setupMemNodeTest(t *testing.T) (wd string, fs *MemNodeFs, clean func()) {
state.Unmount() state.Unmount()
os.RemoveAll(tmp) os.RemoveAll(tmp)
} }
} }
func TestMemNodeFs(t *testing.T) { func TestMemNodeFs(t *testing.T) {
wd, _, clean := setupMemNodeTest(t) wd, _, clean := setupMemNodeTest(t)
defer clean() defer clean()
err := ioutil.WriteFile(wd + "/test", []byte{42}, 0644) err := ioutil.WriteFile(wd+"/test", []byte{42}, 0644)
CheckSuccess(err) CheckSuccess(err)
fi, err := os.Lstat(wd + "/test") fi, err := os.Lstat(wd + "/test")
...@@ -52,10 +52,9 @@ func TestMemNodeFs(t *testing.T) { ...@@ -52,10 +52,9 @@ func TestMemNodeFs(t *testing.T) {
if fi.Size != 1 { if fi.Size != 1 {
t.Errorf("Size after write incorrect: got %d want 1", fi.Size) t.Errorf("Size after write incorrect: got %d want 1", fi.Size)
} }
entries, err := ioutil.ReadDir(wd) entries, err := ioutil.ReadDir(wd)
if len(entries) != 1 || entries[0].Name != "test" { if len(entries) != 1 || entries[0].Name != "test" {
t.Fatalf("Readdir got %v, expected 1 file named 'test'", entries) t.Fatalf("Readdir got %v, expected 1 file named 'test'", entries)
} }
} }
...@@ -91,7 +91,6 @@ func (me *PathNodeFs) Unmount(path string) Status { ...@@ -91,7 +91,6 @@ func (me *PathNodeFs) Unmount(path string) Status {
return me.connector.Unmount(node) return me.connector.Unmount(node)
} }
func (me *PathNodeFs) OnUnmount() { func (me *PathNodeFs) OnUnmount() {
} }
......
...@@ -3,7 +3,7 @@ package unionfs ...@@ -3,7 +3,7 @@ package unionfs
import ( import (
"fmt" "fmt"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -17,9 +17,9 @@ var _ = log.Println ...@@ -17,9 +17,9 @@ var _ = log.Println
type MemUnionFs struct { type MemUnionFs struct {
fuse.DefaultNodeFileSystem fuse.DefaultNodeFileSystem
backingStore string backingStore string
root *memNode root *memNode
mutex sync.Mutex mutex sync.Mutex
nextFree int nextFree int
readonly fuse.FileSystem readonly fuse.FileSystem
...@@ -27,7 +27,7 @@ type MemUnionFs struct { ...@@ -27,7 +27,7 @@ type MemUnionFs struct {
type memNode struct { type memNode struct {
fuse.DefaultFsNode fuse.DefaultFsNode
fs *MemUnionFs fs *MemUnionFs
original string original string
...@@ -108,36 +108,36 @@ func (me *memNode) Readlink(c *fuse.Context) ([]byte, fuse.Status) { ...@@ -108,36 +108,36 @@ func (me *memNode) Readlink(c *fuse.Context) ([]byte, fuse.Status) {
func (me *memNode) Lookup(name string, context *fuse.Context) (fi *os.FileInfo, node fuse.FsNode, code fuse.Status) { func (me *memNode) Lookup(name string, context *fuse.Context) (fi *os.FileInfo, node fuse.FsNode, code fuse.Status) {
me.mutex.RLock() me.mutex.RLock()
defer me.mutex.RUnlock() defer me.mutex.RUnlock()
if _, del := me.deleted[name]; del { if _, del := me.deleted[name]; del {
return nil, nil, fuse.ENOENT return nil, nil, fuse.ENOENT
} }
if me.original == "" && me != me.fs.root { if me.original == "" && me != me.fs.root {
return nil, nil, fuse.ENOENT return nil, nil, fuse.ENOENT
} }
fn := filepath.Join(me.original, name) fn := filepath.Join(me.original, name)
fi, code = me.fs.readonly.GetAttr(fn, context) fi, code = me.fs.readonly.GetAttr(fn, context)
if !code.Ok() { if !code.Ok() {
return nil, nil, code return nil, nil, code
} }
child := me.newNode(fi.Mode & fuse.S_IFDIR != 0) child := me.newNode(fi.Mode&fuse.S_IFDIR != 0)
child.info = *fi child.info = *fi
child.original = fn child.original = fn
if child.info.Mode & fuse.S_IFLNK != 0 { if child.info.Mode&fuse.S_IFLNK != 0 {
child.link, _ = me.fs.readonly.Readlink(fn, context) child.link, _ = me.fs.readonly.Readlink(fn, context)
} }
me.Inode().AddChild(name, child.Inode()) me.Inode().AddChild(name, child.Inode())
return fi, child, fuse.OK return fi, child, fuse.OK
} }
func (me *memNode) Mkdir(name string, mode uint32, context *fuse.Context) (fi *os.FileInfo, newNode fuse.FsNode, code fuse.Status) { func (me *memNode) Mkdir(name string, mode uint32, context *fuse.Context) (fi *os.FileInfo, newNode fuse.FsNode, code fuse.Status) {
me.mutex.Lock() me.mutex.Lock()
defer me.mutex.Unlock() defer me.mutex.Unlock()
me.deleted[name] = false, false me.deleted[name] = false, false
n := me.newNode(true) n := me.newNode(true)
n.changed = true n.changed = true
...@@ -157,7 +157,7 @@ func (me *memNode) Unlink(name string, context *fuse.Context) (code fuse.Status) ...@@ -157,7 +157,7 @@ func (me *memNode) Unlink(name string, context *fuse.Context) (code fuse.Status)
return fuse.ENOENT return fuse.ENOENT
} }
me.touch() me.touch()
return fuse.OK return fuse.OK
} }
...@@ -240,9 +240,9 @@ func (me *memNodeFile) Flush() fuse.Status { ...@@ -240,9 +240,9 @@ func (me *memNodeFile) Flush() fuse.Status {
func (me *memNode) newFile(f fuse.File, writable bool) fuse.File { func (me *memNode) newFile(f fuse.File, writable bool) fuse.File {
return &memNodeFile{ return &memNodeFile{
File: f, File: f,
writable: writable, writable: writable,
node: me, node: me,
} }
} }
...@@ -270,10 +270,10 @@ func (me *memNode) promote() { ...@@ -270,10 +270,10 @@ func (me *memNode) promote() {
} }
func (me *memNode) Open(flags uint32, context *fuse.Context) (file fuse.File, code fuse.Status) { func (me *memNode) Open(flags uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
if flags & fuse.O_ANYWRITE != 0 { if flags&fuse.O_ANYWRITE != 0 {
me.mutex.Lock() me.mutex.Lock()
defer me.mutex.Unlock() defer me.mutex.Unlock()
me.promote() me.promote()
me.touch() me.touch()
} }
...@@ -283,7 +283,7 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (file fuse.File, co ...@@ -283,7 +283,7 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (file fuse.File, co
if err != nil { if err != nil {
return nil, fuse.OsErrorToErrno(err) return nil, fuse.OsErrorToErrno(err)
} }
wr := flags & fuse.O_ANYWRITE != 0 wr := flags&fuse.O_ANYWRITE != 0
return me.newFile(&fuse.LoopbackFile{File: f}, wr), fuse.OK return me.newFile(&fuse.LoopbackFile{File: f}, wr), fuse.OK
} }
...@@ -291,7 +291,7 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (file fuse.File, co ...@@ -291,7 +291,7 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (file fuse.File, co
if !code.Ok() { if !code.Ok() {
return nil, code return nil, code
} }
return me.newFile(file, false), fuse.OK return me.newFile(file, false), fuse.OK
} }
...@@ -342,10 +342,10 @@ func (me *memNode) Chown(file fuse.File, uid uint32, gid uint32, context *fuse.C ...@@ -342,10 +342,10 @@ func (me *memNode) Chown(file fuse.File, uid uint32, gid uint32, context *fuse.C
if context.Uid != 0 { if context.Uid != 0 {
return fuse.EPERM return fuse.EPERM
} }
me.mutex.Lock() me.mutex.Lock()
defer me.mutex.Unlock() defer me.mutex.Unlock()
me.info.Uid = int(uid) me.info.Uid = int(uid)
me.info.Gid = int(gid) me.info.Gid = int(gid)
me.ctouch() me.ctouch()
...@@ -365,7 +365,7 @@ func (me *memNode) OpenDir(context *fuse.Context) (stream chan fuse.DirEntry, co ...@@ -365,7 +365,7 @@ func (me *memNode) OpenDir(context *fuse.Context) (stream chan fuse.DirEntry, co
} }
for k, n := range me.Inode().FsChildren() { for k, n := range me.Inode().FsChildren() {
fi, code := n.FsNode().GetAttr(nil, nil) fi, code := n.FsNode().GetAttr(nil, nil)
if !code.Ok() { if !code.Ok() {
panic("child does not have mode.") panic("child does not have mode.")
} }
......
...@@ -21,7 +21,7 @@ var CheckSuccess = fuse.CheckSuccess ...@@ -21,7 +21,7 @@ var CheckSuccess = fuse.CheckSuccess
func setupMemUfs(t *testing.T) (workdir string, cleanup func()) { func setupMemUfs(t *testing.T) (workdir string, cleanup func()) {
// Make sure system setting does not affect test. // Make sure system setting does not affect test.
syscall.Umask(0) syscall.Umask(0)
wd, _ := ioutil.TempDir("", "") wd, _ := ioutil.TempDir("", "")
err := os.Mkdir(wd+"/mount", 0700) err := os.Mkdir(wd+"/mount", 0700)
fuse.CheckSuccess(err) fuse.CheckSuccess(err)
...@@ -545,7 +545,7 @@ func TestMemUnionFsTruncGetAttr(t *testing.T) { ...@@ -545,7 +545,7 @@ func TestMemUnionFsTruncGetAttr(t *testing.T) {
err = f.Close() err = f.Close()
CheckSuccess(err) CheckSuccess(err)
fi, err := os.Lstat(wd+"/mount/file") fi, err := os.Lstat(wd + "/mount/file")
if fi.Size != int64(len(c)) { if fi.Size != int64(len(c)) {
t.Fatalf("Length mismatch got %d want %d", fi.Size, len(c)) t.Fatalf("Length mismatch got %d want %d", fi.Size, len(c))
} }
......
...@@ -622,12 +622,12 @@ func (me *UnionFs) promoteDirsTo(filename string) fuse.Status { ...@@ -622,12 +622,12 @@ func (me *UnionFs) promoteDirsTo(filename string) fuse.Status {
j := len(todo) - i - 1 j := len(todo) - i - 1
d := todo[j] d := todo[j]
r := results[j] r := results[j]
code := me.fileSystems[0].Mkdir(d, r.attr.Mode & 07777, nil) code := me.fileSystems[0].Mkdir(d, r.attr.Mode&07777, nil)
if code != fuse.OK { if code != fuse.OK {
log.Println("Error creating dir leading to path", d, code) log.Println("Error creating dir leading to path", d, code)
return fuse.EPERM return fuse.EPERM
} }
me.fileSystems[0].Utimens(d, uint64(r.attr.Atime_ns), uint64(r.attr.Mtime_ns), nil) me.fileSystems[0].Utimens(d, uint64(r.attr.Atime_ns), uint64(r.attr.Mtime_ns), nil)
r.branch = 0 r.branch = 0
me.branchCache.Set(d, r) me.branchCache.Set(d, r)
......
...@@ -30,7 +30,7 @@ var testOpts = UnionFsOptions{ ...@@ -30,7 +30,7 @@ var testOpts = UnionFsOptions{
func setupUfs(t *testing.T) (workdir string, cleanup func()) { func setupUfs(t *testing.T) (workdir string, cleanup func()) {
// Make sure system setting does not affect test. // Make sure system setting does not affect test.
syscall.Umask(0) syscall.Umask(0)
wd, _ := ioutil.TempDir("", "") wd, _ := ioutil.TempDir("", "")
err := os.Mkdir(wd+"/mount", 0700) err := os.Mkdir(wd+"/mount", 0700)
fuse.CheckSuccess(err) fuse.CheckSuccess(err)
...@@ -1061,13 +1061,12 @@ func TestTruncGetAttr(t *testing.T) { ...@@ -1061,13 +1061,12 @@ func TestTruncGetAttr(t *testing.T) {
err = f.Close() err = f.Close()
CheckSuccess(err) CheckSuccess(err)
fi, err := os.Lstat(wd+"/mount/file") fi, err := os.Lstat(wd + "/mount/file")
if fi.Size != int64(len(c)) { if fi.Size != int64(len(c)) {
t.Fatalf("Length mismatch got %d want %d", fi.Size, len(c)) t.Fatalf("Length mismatch got %d want %d", fi.Size, len(c))
} }
} }
func TestPromoteDirTimeStamp(t *testing.T) { func TestPromoteDirTimeStamp(t *testing.T) {
wd, clean := setupUfs(t) wd, clean := setupUfs(t)
defer clean() defer clean()
...@@ -1076,7 +1075,7 @@ func TestPromoteDirTimeStamp(t *testing.T) { ...@@ -1076,7 +1075,7 @@ func TestPromoteDirTimeStamp(t *testing.T) {
CheckSuccess(err) CheckSuccess(err)
err = ioutil.WriteFile(wd+"/ro/subdir/file", []byte("hello"), 0644) err = ioutil.WriteFile(wd+"/ro/subdir/file", []byte("hello"), 0644)
CheckSuccess(err) CheckSuccess(err)
err = os.Chmod(wd+"/mount/subdir/file", 0060) err = os.Chmod(wd+"/mount/subdir/file", 0060)
CheckSuccess(err) CheckSuccess(err)
......
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