From 8278f60eb3a49236c51d9d5280a3d9da4096ec1c Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys <hanwen@google.com> Date: Thu, 29 Sep 2011 00:29:10 -0300 Subject: [PATCH] Run gofmt. --- example/unionfs/main.go | 2 +- fuse/files.go | 1 - fuse/fsconnector.go | 2 +- fuse/fsops.go | 2 +- fuse/loopback_test.go | 6 +++--- fuse/memnode.go | 2 +- fuse/opcode.go | 18 +++++++++--------- fuse/prefixfs.go | 2 +- unionfs/memunionfs.go | 17 ++++++++--------- unionfs/memunionfs_test.go | 30 +++++++++++++++--------------- unionfs/unionfs.go | 7 +++---- unionfs/unionfs_test.go | 34 +++++++++++++++++----------------- 12 files changed, 60 insertions(+), 63 deletions(-) diff --git a/example/unionfs/main.go b/example/unionfs/main.go index db45b63..92b495f 100644 --- a/example/unionfs/main.go +++ b/example/unionfs/main.go @@ -30,7 +30,7 @@ func main() { var nodeFs fuse.NodeFileSystem if *mem { nodeFs = unionfs.NewMemUnionFs( - flag.Arg(1) + "/", &fuse.LoopbackFileSystem{Root: flag.Arg(2)}) + flag.Arg(1)+"/", &fuse.LoopbackFileSystem{Root: flag.Arg(2)}) } else { ufsOptions := unionfs.UnionFsOptions{ DeletionCacheTTLSecs: *delcache_ttl, diff --git a/fuse/files.go b/fuse/files.go index 1f24dd9..c3d96eb 100644 --- a/fuse/files.go +++ b/fuse/files.go @@ -59,7 +59,6 @@ func (me *DevNullFile) String() string { return "DevNullFile" } - func (me *DevNullFile) Read(input *ReadIn, bp BufferPool) ([]byte, Status) { return []byte{}, OK } diff --git a/fuse/fsconnector.go b/fuse/fsconnector.go index 0693586..8b580a3 100644 --- a/fuse/fsconnector.go +++ b/fuse/fsconnector.go @@ -192,7 +192,7 @@ func (me *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []s node.treeLock.RLock() defer node.treeLock.RUnlock() } - + for i, component := range comps { if len(component) == 0 { continue diff --git a/fuse/fsops.go b/fuse/fsops.go index 610e0e7..458af24 100644 --- a/fuse/fsops.go +++ b/fuse/fsops.go @@ -66,7 +66,7 @@ func (me *FileSystemConnector) Lookup(header *InHeader, name string) (out *Entry out.NodeId = me.lookupUpdate(child) out.Generation = 1 out.Ino = out.NodeId - + return out, OK } diff --git a/fuse/loopback_test.go b/fuse/loopback_test.go index b1bbb4e..d890bc1 100644 --- a/fuse/loopback_test.go +++ b/fuse/loopback_test.go @@ -714,14 +714,14 @@ func TestFStatFs(t *testing.T) { fOrig, err := os.OpenFile(ts.orig+"/file", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644) CheckSuccess(err) defer fOrig.Close() - + empty := syscall.Statfs_t{} s1 := empty errno := syscall.Fstatfs(fOrig.Fd(), &s1) if errno != 0 { t.Fatal("statfs orig", err) } - + fMnt, err := os.OpenFile(ts.mnt+"/file", os.O_RDWR, 0644) CheckSuccess(err) defer fMnt.Close() @@ -731,7 +731,7 @@ func TestFStatFs(t *testing.T) { if errno != 0 { t.Fatal("statfs mnt", err) } - + clearStatfs(&s1) clearStatfs(&s2) if fmt.Sprintf("%v", s2) != fmt.Sprintf("%v", s1) { diff --git a/fuse/memnode.go b/fuse/memnode.go index 6c1af51..06db580 100644 --- a/fuse/memnode.go +++ b/fuse/memnode.go @@ -13,7 +13,7 @@ var _ = log.Println type MemNodeFs struct { DefaultNodeFileSystem backingStorePrefix string - root *memNode + root *memNode mutex sync.Mutex nextFree int diff --git a/fuse/opcode.go b/fuse/opcode.go index 6632afa..1329d73 100644 --- a/fuse/opcode.go +++ b/fuse/opcode.go @@ -302,13 +302,13 @@ type operationFunc func(*MountState, *request) type castPointerFunc func(unsafe.Pointer) interface{} type operationHandler struct { - Name string - Func operationFunc - InputSize uintptr - OutputSize uintptr - DecodeIn castPointerFunc - DecodeOut castPointerFunc - FileNames int + Name string + Func operationFunc + InputSize uintptr + OutputSize uintptr + DecodeIn castPointerFunc + DecodeOut castPointerFunc + FileNames int FileNameOut bool } @@ -339,11 +339,11 @@ func init() { operationHandlers[i] = &operationHandler{Name: "UNKNOWN"} } - fileOps := []opcode{_OP_READLINK, _OP_NOTIFY_ENTRY} + fileOps := []opcode{_OP_READLINK, _OP_NOTIFY_ENTRY} for _, op := range fileOps { operationHandlers[op].FileNameOut = true } - + for op, sz := range map[opcode]uintptr{ _OP_FORGET: unsafe.Sizeof(ForgetIn{}), _OP_GETATTR: unsafe.Sizeof(GetAttrIn{}), diff --git a/fuse/prefixfs.go b/fuse/prefixfs.go index aa97096..cf781eb 100644 --- a/fuse/prefixfs.go +++ b/fuse/prefixfs.go @@ -14,7 +14,7 @@ type PrefixFileSystem struct { func (me *PrefixFileSystem) prefixed(n string) string { return filepath.Join(me.Prefix, n) -} +} func (me *PrefixFileSystem) GetAttr(name string, context *Context) (*os.FileInfo, Status) { return me.FileSystem.GetAttr(me.prefixed(name), context) diff --git a/unionfs/memunionfs.go b/unionfs/memunionfs.go index 905451e..87e8611 100644 --- a/unionfs/memunionfs.go +++ b/unionfs/memunionfs.go @@ -20,9 +20,9 @@ type MemUnionFs struct { backingStore string root *memNode connector *fuse.FileSystemConnector - mutex sync.RWMutex - cond *sync.Cond - nextFree int + mutex sync.RWMutex + cond *sync.Cond + nextFree int readonly fuse.FileSystem @@ -31,7 +31,7 @@ type MemUnionFs struct { // All paths that have been renamed or deleted will be marked // here. After deletion, entries may be recreated, but they // will be treated as new. - deleted map[string]bool + deleted map[string]bool } type memNode struct { @@ -87,7 +87,7 @@ func (me *MemUnionFs) Reap() map[string]*Result { todo := []string{name} for len(todo) > 0 { - l := len(todo)-1 + l := len(todo) - 1 n := todo[l] todo = todo[:l] @@ -95,7 +95,7 @@ func (me *MemUnionFs) Reap() map[string]*Result { for e := range s { full := filepath.Join(n, e.Name) m[full] = &Result{} - if e.Mode & fuse.S_IFDIR != 0 { + if e.Mode&fuse.S_IFDIR != 0 { todo = append(todo, full) } } @@ -137,7 +137,7 @@ func (me *MemUnionFs) Update(results map[string]*Result) { } sort.Strings(del) - for i := len(del)-1; i >= 0; i-- { + for i := len(del) - 1; i >= 0; i-- { n := del[i] dir, base := filepath.Split(n) dir = strings.TrimRight(dir, "/") @@ -600,7 +600,7 @@ func (me *memNode) Reap(path string, results map[string]*Result) { if me.changed { info := me.info results[path] = &Result{ - FileInfo: &info, + FileInfo: &info, Link: me.link, Backing: me.backing, Original: me.original, @@ -633,4 +633,3 @@ func (me *memNode) Clear(path string) { mn.Clear(p) } } - diff --git a/unionfs/memunionfs_test.go b/unionfs/memunionfs_test.go index 0af16f1..0bbf216 100644 --- a/unionfs/memunionfs_test.go +++ b/unionfs/memunionfs_test.go @@ -32,7 +32,7 @@ func setupMemUfs(t *testing.T) (workdir string, ufs *MemUnionFs, cleanup func()) os.Mkdir(wd+"/ro", 0700) fuse.CheckSuccess(err) - roFs := fuse.NewLoopbackFileSystem(wd+"/ro") + roFs := fuse.NewLoopbackFileSystem(wd + "/ro") memFs := NewMemUnionFs(wd+"/backing", roFs) // We configure timeouts are smaller, so we can check for @@ -84,7 +84,7 @@ func TestMemUnionFsSymlinkPromote(t *testing.T) { err = os.Symlink("/foobar", wd+"/mount/subdir/link") CheckSuccess(err) - + r := ufs.Reap() if len(r) != 2 || r["subdir"] == nil || r["subdir/link"] == nil || r["subdir/link"].Link != "/foobar" { t.Errorf("expect 1 symlink reap result: %v", r) @@ -231,7 +231,7 @@ func TestMemUnionFsSubdirCreate(t *testing.T) { writeToFile(wd+"/mount/subdir/sub2/file", "other-content") _, err = os.Lstat(wd + "/mount/subdir/sub2/file") CheckSuccess(err) - + r := ufs.Reap() if r["subdir/sub2/file"] == nil || r["subdir/sub2/file"].Backing == "" { t.Errorf("expect 1 file reap result: %v", r) @@ -245,7 +245,7 @@ func TestMemUnionFsCreate(t *testing.T) { writeToFile(wd+"/mount/file.txt", "hello") _, err := os.Lstat(wd + "/mount/file.txt") CheckSuccess(err) - + r := ufs.Reap() if r["file.txt"] == nil || r["file.txt"].Backing == "" { t.Errorf("expect 1 file reap result: %v", r) @@ -292,7 +292,7 @@ func TestMemUnionFsMkdirPromote(t *testing.T) { CheckSuccess(err) r := ufs.Reap() - if r["subdir/subdir2/dir3"] == nil || r["subdir/subdir2/dir3"].FileInfo.Mode & fuse.S_IFDIR == 0 { + if r["subdir/subdir2/dir3"] == nil || r["subdir/subdir2/dir3"].FileInfo.Mode&fuse.S_IFDIR == 0 { t.Errorf("expect 1 file reap result: %v", r) } } @@ -504,7 +504,7 @@ func TestMemUnionFsDoubleOpen(t *testing.T) { func TestMemUnionFsUpdate(t *testing.T) { wd, ufs, clean := setupMemUfs(t) defer clean() - + err := ioutil.WriteFile(wd+"/ro/file1", []byte("blablabla"), 0644) CheckSuccess(err) @@ -516,14 +516,14 @@ func TestMemUnionFsUpdate(t *testing.T) { if fi, _ := os.Lstat(wd + "/mount/symlink"); fi != nil { t.Fatal("symlink should not exist", fi) } - - err = os.Remove(wd+"/ro/file1") + + err = os.Remove(wd + "/ro/file1") CheckSuccess(err) err = ioutil.WriteFile(wd+"/ro/file2", []byte("foobar"), 0644) CheckSuccess(err) - err = os.Symlink("target", wd + "/ro/symlink") + err = os.Symlink("target", wd+"/ro/symlink") CheckSuccess(err) - + // Still have cached attributes. fi, err := os.Lstat(wd + "/mount/file1") CheckSuccess(err) @@ -538,7 +538,7 @@ func TestMemUnionFsUpdate(t *testing.T) { CheckSuccess(err) roSymlinkFi, err := os.Lstat(wd + "/ro/symlink") CheckSuccess(err) - + updates := map[string]*Result{ "file1": &Result{ nil, "", "", "", @@ -702,7 +702,7 @@ func TestMemUnionFsRenameDirBasic(t *testing.T) { if r["dir"] == nil || r["dir"].FileInfo != nil || r["renamed/subdir"] == nil || !r["renamed/subdir"].FileInfo.IsDirectory() { t.Errorf("Reap should del dir, and add renamed/subdir: %v", r) } - + if err = os.Mkdir(wd+"/mount/dir", 0755); err != nil { t.Errorf("mkdir should succeed %v", err) } @@ -782,11 +782,11 @@ func TestMemUnionGc(t *testing.T) { writeToFile(wd+"/mount/file1", "other-content") writeToFile(wd+"/mount/file2", "other-content") - err := os.Remove(wd+"/mount/file1") + err := os.Remove(wd + "/mount/file1") CheckSuccess(err) ufs.Clear() - - entries, err := ioutil.ReadDir(wd+"/backing") + + entries, err := ioutil.ReadDir(wd + "/backing") CheckSuccess(err) if len(entries) != 0 { t.Fatalf("should have 1 file after backing store gc: %v", entries) diff --git a/unionfs/unionfs.go b/unionfs/unionfs.go index 3076a79..66f05ab 100644 --- a/unionfs/unionfs.go +++ b/unionfs/unionfs.go @@ -280,7 +280,7 @@ func (me *UnionFs) Promote(name string, srcResult branchResult, context *fuse.Co code = fuse.CopyFile(sourceFs, writable, name, name, context) if code.Ok() { - code = writable.Chmod(name, srcResult.attr.Mode & 07777 | 0200, context) + code = writable.Chmod(name, srcResult.attr.Mode&07777|0200, context) } if code.Ok() { code = writable.Utimens(name, uint64(srcResult.attr.Atime_ns), @@ -321,13 +321,12 @@ func (me *UnionFs) Promote(name string, srcResult branchResult, context *fuse.Co code = writable.Symlink(link, name, context) } } else if srcResult.attr.IsDirectory() { - code = writable.Mkdir(name, srcResult.attr.Mode & 07777 | 0200, context) + code = writable.Mkdir(name, srcResult.attr.Mode&07777|0200, context) } else { log.Println("Unknown file type:", srcResult.attr) return fuse.ENOSYS } - if !code.Ok() { me.branchCache.GetFresh(name) return code @@ -635,7 +634,7 @@ func (me *UnionFs) promoteDirsTo(filename string) fuse.Status { j := len(todo) - i - 1 d := todo[j] r := results[j] - code := me.fileSystems[0].Mkdir(d, r.attr.Mode&07777 | 0200, nil) + code := me.fileSystems[0].Mkdir(d, r.attr.Mode&07777|0200, nil) if code != fuse.OK { log.Println("Error creating dir leading to path", d, code, me.fileSystems[0]) return fuse.EPERM diff --git a/unionfs/unionfs_test.go b/unionfs/unionfs_test.go index 776e25b..30bfe52 100644 --- a/unionfs/unionfs_test.go +++ b/unionfs/unionfs_test.go @@ -31,8 +31,8 @@ func freezeRo(dir string) { err := filepath.Walk( dir, func(path string, fi *os.FileInfo, err os.Error) os.Error { - return os.Chmod(path, (fi.Mode & 0777) &^ 0222) - }) + return os.Chmod(path, (fi.Mode&0777)&^0222) + }) CheckSuccess(err) } @@ -493,7 +493,7 @@ func TestUnionFsRenameDirAllSourcesGone(t *testing.T) { err = ioutil.WriteFile(wd+"/ro/dir/file.txt", []byte{42}, 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") err = os.Rename(wd+"/mount/dir", wd+"/mount/renamed") CheckSuccess(err) @@ -515,7 +515,7 @@ func TestUnionFsRenameDirWithDeletions(t *testing.T) { err = ioutil.WriteFile(wd+"/ro/dir/subdir/file.txt", []byte{42}, 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") if fi, _ := os.Lstat(wd + "/mount/dir/subdir/file.txt"); fi == nil || !fi.IsRegular() { t.Fatalf("%s/mount/dir/subdir/file.txt should be file: %v", wd, fi) @@ -582,7 +582,7 @@ func TestUnionFsWritableDir(t *testing.T) { dirname := wd + "/ro/subdir" err := os.Mkdir(dirname, 0555) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") fi, err := os.Lstat(wd + "/mount/subdir") CheckSuccess(err) @@ -599,7 +599,7 @@ func TestUnionFsWriteAccess(t *testing.T) { // No write perms. err := ioutil.WriteFile(fn, []byte("foo"), 0444) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") errno := syscall.Access(wd+"/mount/file", fuse.W_OK) if errno != 0 { @@ -616,7 +616,7 @@ func TestUnionFsLink(t *testing.T) { fn := wd + "/ro/file" err := ioutil.WriteFile(fn, []byte(content), 0666) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") err = os.Link(wd+"/mount/file", wd+"/mount/linked") CheckSuccess(err) @@ -640,7 +640,7 @@ func TestUnionFsTruncate(t *testing.T) { defer clean() writeToFile(wd+"/ro/file", "hello") - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") os.Truncate(wd+"/mount/file", 2) content := readFromFile(wd + "/mount/file") @@ -718,7 +718,7 @@ func TestUnionFsRemoveAll(t *testing.T) { fn := wd + "/ro/dir/subdir/y" err = ioutil.WriteFile(fn, []byte(contents), 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") err = os.RemoveAll(wd + "/mount/dir") if err != nil { @@ -749,7 +749,7 @@ func TestUnionFsRmRf(t *testing.T) { fn := wd + "/ro/dir/subdir/y" err = ioutil.WriteFile(fn, []byte(contents), 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") bin, err := exec.LookPath("rm") CheckSuccess(err) @@ -788,7 +788,7 @@ func TestUnionFsDropDeletionCache(t *testing.T) { err := ioutil.WriteFile(wd+"/ro/file", []byte("bla"), 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") _, err = os.Lstat(wd + "/mount/file") CheckSuccess(err) @@ -887,7 +887,7 @@ func TestUnionFsDisappearing(t *testing.T) { err = ioutil.WriteFile(wd+"/ro/file", []byte("blabla"), 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") err = os.Remove(wd + "/mount/file") CheckSuccess(err) @@ -928,7 +928,7 @@ func TestUnionFsDeletedGetAttr(t *testing.T) { err := ioutil.WriteFile(wd+"/ro/file", []byte("blabla"), 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") f, err := os.Open(wd + "/mount/file") CheckSuccess(err) @@ -947,7 +947,7 @@ func TestUnionFsDoubleOpen(t *testing.T) { defer clean() err := ioutil.WriteFile(wd+"/ro/file", []byte("blablabla"), 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") roFile, err := os.Open(wd + "/mount/file") CheckSuccess(err) @@ -985,7 +985,7 @@ func TestUnionFsFdLeak(t *testing.T) { wd, clean := setupUfs(t) err = ioutil.WriteFile(wd+"/ro/file", []byte("blablabla"), 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") contents, err := ioutil.ReadFile(wd + "/mount/file") CheckSuccess(err) @@ -1091,7 +1091,7 @@ func TestUnionFsPromoteDirTimeStamp(t *testing.T) { CheckSuccess(err) err = ioutil.WriteFile(wd+"/ro/subdir/file", []byte("hello"), 0644) CheckSuccess(err) - freezeRo(wd+"/ro") + freezeRo(wd + "/ro") err = os.Chmod(wd+"/mount/subdir/file", 0060) CheckSuccess(err) @@ -1107,7 +1107,7 @@ func TestUnionFsPromoteDirTimeStamp(t *testing.T) { t.Errorf("Changed timestamps on promoted subdir: ro %d rw %d", fRo.Mtime_ns, fRw.Mtime_ns) } - if fRo.Mode | 0200 != fRw.Mode { + if fRo.Mode|0200 != fRw.Mode { t.Errorf("Changed mode ro: %o, rw: %o", fRo.Mode, fRw.Mode) } } -- 2.30.9