Commit 2d65aab9 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Run gofmt.

parent ed34f5da
...@@ -97,7 +97,7 @@ type FileSystemOptions struct { ...@@ -97,7 +97,7 @@ type FileSystemOptions struct {
} }
type MountOptions struct { type MountOptions struct {
AllowOther bool AllowOther bool
} }
// DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation. // DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
......
package fuse package fuse
import ( import (
"os" "os"
"fmt" "fmt"
......
...@@ -65,10 +65,10 @@ func (me *testCase) Setup(t *testing.T) { ...@@ -65,10 +65,10 @@ func (me *testCase) Setup(t *testing.T) {
var rfs RawFileSystem var rfs RawFileSystem
me.connector = NewFileSystemConnector(pfs, me.connector = NewFileSystemConnector(pfs,
&FileSystemOptions{ &FileSystemOptions{
EntryTimeout: testTtl, EntryTimeout: testTtl,
AttrTimeout: testTtl, AttrTimeout: testTtl,
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
}) })
rfs = me.connector rfs = me.connector
rfs = NewTimingRawFileSystem(rfs) rfs = NewTimingRawFileSystem(rfs)
rfs = NewLockingRawFileSystem(rfs) rfs = NewLockingRawFileSystem(rfs)
...@@ -601,7 +601,7 @@ func TestLargeRead(t *testing.T) { ...@@ -601,7 +601,7 @@ func TestLargeRead(t *testing.T) {
ts := new(testCase) ts := new(testCase)
ts.Setup(t) ts.Setup(t)
defer ts.Cleanup() defer ts.Cleanup()
ts.testLargeRead() ts.testLargeRead()
} }
...@@ -609,7 +609,7 @@ func TestLargeDirRead(t *testing.T) { ...@@ -609,7 +609,7 @@ func TestLargeDirRead(t *testing.T) {
ts := new(testCase) ts := new(testCase)
ts.Setup(t) ts.Setup(t)
defer ts.Cleanup() defer ts.Cleanup()
ts.testLargeDirRead() ts.testLargeDirRead()
} }
...@@ -680,9 +680,9 @@ func TestRecursiveMount(t *testing.T) { ...@@ -680,9 +680,9 @@ func TestRecursiveMount(t *testing.T) {
t.Error("expect EBUSY") t.Error("expect EBUSY")
} }
err = os.Rename(ts.mountPoint + "/mnt", ts.mountPoint + "/foobar") err = os.Rename(ts.mountPoint+"/mnt", ts.mountPoint+"/foobar")
CheckSuccess(err) CheckSuccess(err)
f.Close() f.Close()
log.Println("Waiting for kernel to flush file-close to fuse...") log.Println("Waiting for kernel to flush file-close to fuse...")
...@@ -702,11 +702,11 @@ func TestDeletedUnmount(t *testing.T) { ...@@ -702,11 +702,11 @@ func TestDeletedUnmount(t *testing.T) {
ts := new(testCase) ts := new(testCase)
ts.Setup(t) ts.Setup(t)
defer ts.Cleanup() defer ts.Cleanup()
submnt := filepath.Join(ts.mountPoint, "mnt") submnt := filepath.Join(ts.mountPoint, "mnt")
err := os.Mkdir(submnt, 0777) err := os.Mkdir(submnt, 0777)
CheckSuccess(err) CheckSuccess(err)
pfs2 := NewLoopbackFileSystem(ts.origDir) pfs2 := NewLoopbackFileSystem(ts.origDir)
code := ts.connector.Mount("/mnt", pfs2, nil) code := ts.connector.Mount("/mnt", pfs2, nil)
if !code.Ok() { if !code.Ok() {
......
...@@ -185,8 +185,7 @@ func ReverseJoin(rev_components []string, sep string) string { ...@@ -185,8 +185,7 @@ func ReverseJoin(rev_components []string, sep string) string {
func CurrentOwner() *Owner { func CurrentOwner() *Owner {
return &Owner{ return &Owner{
Uid: uint32(os.Getuid()), Uid: uint32(os.Getuid()),
Gid: uint32(os.Getgid()), Gid: uint32(os.Getgid()),
} }
} }
...@@ -50,13 +50,13 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin ...@@ -50,13 +50,13 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin
} }
mountPoint = filepath.Clean(filepath.Join(cwd, mountPoint)) mountPoint = filepath.Clean(filepath.Join(cwd, mountPoint))
} }
cmd := []string{"/bin/fusermount", mountPoint} cmd := []string{"/bin/fusermount", mountPoint}
if options != "" { if options != "" {
cmd = append(cmd, "-o") cmd = append(cmd, "-o")
cmd = append(cmd, options) cmd = append(cmd, options)
} }
proc, err := os.StartProcess("/bin/fusermount", proc, err := os.StartProcess("/bin/fusermount",
cmd, cmd,
&os.ProcAttr{ &os.ProcAttr{
......
...@@ -51,7 +51,7 @@ func (me *MountState) Mount(mountPoint string, opts *MountOptions) os.Error { ...@@ -51,7 +51,7 @@ func (me *MountState) Mount(mountPoint string, opts *MountOptions) os.Error {
if opts != nil && opts.AllowOther { if opts != nil && opts.AllowOther {
optStr = "allow_other" optStr = "allow_other"
} }
file, mp, err := mount(mountPoint, optStr) file, mp, err := mount(mountPoint, optStr)
if err != nil { if err != nil {
return err return err
......
...@@ -20,8 +20,8 @@ func (me *ownerFs) GetAttr(name string) (*os.FileInfo, Status) { ...@@ -20,8 +20,8 @@ func (me *ownerFs) GetAttr(name string) (*os.FileInfo, Status) {
} }
return &os.FileInfo{ return &os.FileInfo{
Mode: S_IFREG | 0644, Mode: S_IFREG | 0644,
Uid: _RANDOM_OWNER, Uid: _RANDOM_OWNER,
Gid: _RANDOM_OWNER, Gid: _RANDOM_OWNER,
}, OK }, OK
} }
...@@ -70,4 +70,3 @@ func TestOwnerOverride(t *testing.T) { ...@@ -70,4 +70,3 @@ func TestOwnerOverride(t *testing.T) {
t.Fatal("Should use current uid for mount", fi.Uid, fi.Gid) t.Fatal("Should use current uid for mount", fi.Uid, fi.Gid)
} }
} }
...@@ -80,14 +80,14 @@ func (me *FileSystemDebug) GetAttr(path string) (*os.FileInfo, Status) { ...@@ -80,14 +80,14 @@ func (me *FileSystemDebug) GetAttr(path string) (*os.FileInfo, Status) {
if path == DebugDir { if path == DebugDir {
return &os.FileInfo{ return &os.FileInfo{
Mode: S_IFDIR | 0755, Mode: S_IFDIR | 0755,
},OK }, OK
} }
c := me.getContent(path) c := me.getContent(path)
if c != nil { if c != nil {
return &os.FileInfo{ return &os.FileInfo{
Mode: S_IFREG | 0644, Mode: S_IFREG | 0644,
Size: int64(len(c)), Size: int64(len(c)),
},OK }, OK
} }
return nil, ENOENT return nil, ENOENT
} }
......
...@@ -58,9 +58,9 @@ type mountData struct { ...@@ -58,9 +58,9 @@ type mountData struct {
// Protects parent/child relations within the mount. // Protects parent/child relations within the mount.
// treeLock should be acquired before openFilesLock // treeLock should be acquired before openFilesLock
treeLock sync.RWMutex treeLock sync.RWMutex
// Protects openFiles // Protects openFiles
openFilesLock sync.RWMutex openFilesLock sync.RWMutex
// Open files/directories. // Open files/directories.
openFiles map[uint64]*fileBridge openFiles map[uint64]*fileBridge
...@@ -68,7 +68,7 @@ type mountData struct { ...@@ -68,7 +68,7 @@ type mountData struct {
func newMount(fs FileSystem) *mountData { func newMount(fs FileSystem) *mountData {
return &mountData{ return &mountData{
fs: fs, fs: fs,
openFiles: make(map[uint64]*fileBridge), openFiles: make(map[uint64]*fileBridge),
} }
} }
...@@ -126,14 +126,14 @@ type inode struct { ...@@ -126,14 +126,14 @@ type inode struct {
// Protected by openFilesLock. // Protected by openFilesLock.
// TODO - verify() this variable too. // TODO - verify() this variable too.
OpenCount int OpenCount int
// Non-nil if this is a mountpoint. // Non-nil if this is a mountpoint.
mountPoint *mountData mountPoint *mountData
// The point under which this node is. Should be non-nil for // The point under which this node is. Should be non-nil for
// all nodes. // all nodes.
mount *mountData mount *mountData
} }
// TotalOpenCount counts open files. It should only be entered from // TotalOpenCount counts open files. It should only be entered from
...@@ -143,7 +143,7 @@ func (me *inode) TotalOpenCount() int { ...@@ -143,7 +143,7 @@ func (me *inode) TotalOpenCount() int {
if me.mountPoint != nil { if me.mountPoint != nil {
me.mountPoint.treeLock.RLock() me.mountPoint.treeLock.RLock()
defer me.mountPoint.treeLock.RUnlock() defer me.mountPoint.treeLock.RUnlock()
me.mountPoint.openFilesLock.RLock() me.mountPoint.openFilesLock.RLock()
defer me.mountPoint.openFilesLock.RUnlock() defer me.mountPoint.openFilesLock.RUnlock()
...@@ -164,12 +164,12 @@ func (me *inode) TotalMountCount() int { ...@@ -164,12 +164,12 @@ func (me *inode) TotalMountCount() int {
if me.mountPoint.unmountPending { if me.mountPoint.unmountPending {
return 0 return 0
} }
o++ o++
me.mountPoint.treeLock.RLock() me.mountPoint.treeLock.RLock()
defer me.mountPoint.treeLock.RUnlock() defer me.mountPoint.treeLock.RUnlock()
} }
for _, v := range me.Children { for _, v := range me.Children {
o += v.TotalMountCount() o += v.TotalMountCount()
} }
...@@ -196,7 +196,7 @@ func (me *inode) verify(cur *mountData) { ...@@ -196,7 +196,7 @@ func (me *inode) verify(cur *mountData) {
if me.mount != cur { if me.mount != cur {
panic(fmt.Sprintf("me.mount not set correctly %v %v", me.mount, cur)) panic(fmt.Sprintf("me.mount not set correctly %v %v", me.mount, cur))
} }
for n, ch := range me.Children { for n, ch := range me.Children {
if ch == nil { if ch == nil {
panic("Found nil child.") panic("Found nil child.")
...@@ -230,7 +230,7 @@ func (me *inode) GetPath() (path string, mount *mountData) { ...@@ -230,7 +230,7 @@ func (me *inode) GetPath() (path string, mount *mountData) {
// Deleted node. Treat as if the filesystem was unmounted. // Deleted node. Treat as if the filesystem was unmounted.
return ".deleted", nil return ".deleted", nil
} }
rev_components := make([]string, 0, 10) rev_components := make([]string, 0, 10)
inode := me inode := me
...@@ -292,7 +292,7 @@ func NewFileSystemOptions() *FileSystemOptions { ...@@ -292,7 +292,7 @@ func NewFileSystemOptions() *FileSystemOptions {
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
AttrTimeout: 1.0, AttrTimeout: 1.0,
EntryTimeout: 1.0, EntryTimeout: 1.0,
Owner: CurrentOwner(), Owner: CurrentOwner(),
} }
} }
...@@ -402,7 +402,7 @@ func (me *FileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int) { ...@@ -402,7 +402,7 @@ func (me *FileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int) {
defer me.verify() defer me.verify()
node := me.getInodeData(nodeId) node := me.getInodeData(nodeId)
node.LookupCount -= forgetCount node.LookupCount -= forgetCount
me.considerDropInode(node) me.considerDropInode(node)
} }
...@@ -410,15 +410,15 @@ func (me *FileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int) { ...@@ -410,15 +410,15 @@ func (me *FileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int) {
func (me *FileSystemConnector) considerDropInode(n *inode) { func (me *FileSystemConnector) considerDropInode(n *inode) {
n.mount.treeLock.Lock() n.mount.treeLock.Lock()
defer n.mount.treeLock.Unlock() defer n.mount.treeLock.Unlock()
if n.LookupCount <= 0 && len(n.Children) == 0 && (n.mountPoint == nil || n.mountPoint.unmountPending) && if n.LookupCount <= 0 && len(n.Children) == 0 && (n.mountPoint == nil || n.mountPoint.unmountPending) &&
n.OpenCount <= 0 { n.OpenCount <= 0 {
n.setParent(nil) n.setParent(nil)
me.inodeMapMutex.Lock() me.inodeMapMutex.Lock()
defer me.inodeMapMutex.Unlock() defer me.inodeMapMutex.Unlock()
me.inodeMap[n.NodeId] = nil, false me.inodeMap[n.NodeId] = nil, false
} }
} }
func (me *FileSystemConnector) renameUpdate(oldParent *inode, oldName string, newParent *inode, newName string) { func (me *FileSystemConnector) renameUpdate(oldParent *inode, oldName string, newParent *inode, newName string) {
...@@ -470,7 +470,7 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode { ...@@ -470,7 +470,7 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode {
node.mountPoint.treeLock.RLock() node.mountPoint.treeLock.RLock()
defer node.mountPoint.treeLock.RUnlock() defer node.mountPoint.treeLock.RUnlock()
} }
node = node.Children[component] node = node.Children[component]
if node == nil { if node == nil {
return nil return nil
...@@ -525,7 +525,7 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Fil ...@@ -525,7 +525,7 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Fil
if node != me.rootNode { if node != me.rootNode {
node.mount.treeLock.RUnlock() node.mount.treeLock.RUnlock()
} }
if hasChildren { if hasChildren {
return EBUSY return EBUSY
} }
......
...@@ -492,4 +492,3 @@ func (me *FileSystemConnector) Ioctl(header *InHeader, input *IoctlIn) (out *Ioc ...@@ -492,4 +492,3 @@ func (me *FileSystemConnector) Ioctl(header *InHeader, input *IoctlIn) (out *Ioc
} }
return f.Ioctl(input) return f.Ioctl(input)
} }
...@@ -39,11 +39,11 @@ type AutoUnionFsOptions struct { ...@@ -39,11 +39,11 @@ type AutoUnionFsOptions struct {
} }
const ( const (
_READONLY = "READONLY" _READONLY = "READONLY"
_STATUS = "status" _STATUS = "status"
_CONFIG = "config" _CONFIG = "config"
_ROOT = "root" _ROOT = "root"
_VERSION = "gounionfs_version" _VERSION = "gounionfs_version"
_SCAN_CONFIG = ".scan_config" _SCAN_CONFIG = ".scan_config"
) )
...@@ -258,7 +258,7 @@ func (me *AutoUnionFs) GetAttr(path string) (*os.FileInfo, fuse.Status) { ...@@ -258,7 +258,7 @@ func (me *AutoUnionFs) GetAttr(path string) (*os.FileInfo, fuse.Status) {
} }
return a, fuse.OK return a, fuse.OK
} }
if path == filepath.Join(_CONFIG, _SCAN_CONFIG) { if path == filepath.Join(_CONFIG, _SCAN_CONFIG) {
a := &os.FileInfo{ a := &os.FileInfo{
Mode: fuse.S_IFREG | 0644, Mode: fuse.S_IFREG | 0644,
...@@ -283,7 +283,7 @@ func (me *AutoUnionFs) GetAttr(path string) (*os.FileInfo, fuse.Status) { ...@@ -283,7 +283,7 @@ func (me *AutoUnionFs) GetAttr(path string) (*os.FileInfo, fuse.Status) {
if me.getUnionFs(path) != nil { if me.getUnionFs(path) != nil {
return &os.FileInfo{ return &os.FileInfo{
Mode: fuse.S_IFDIR | 0755, Mode: fuse.S_IFDIR | 0755,
},fuse.OK }, fuse.OK
} }
return nil, fuse.ENOENT return nil, fuse.ENOENT
...@@ -306,13 +306,13 @@ func (me *AutoUnionFs) StatusDir() (stream chan fuse.DirEntry, status fuse.Statu ...@@ -306,13 +306,13 @@ func (me *AutoUnionFs) StatusDir() (stream chan fuse.DirEntry, status fuse.Statu
func (me *AutoUnionFs) Open(path string, flags uint32) (fuse.File, fuse.Status) { func (me *AutoUnionFs) Open(path string, flags uint32) (fuse.File, fuse.Status) {
if path == filepath.Join(_STATUS, _VERSION) { if path == filepath.Join(_STATUS, _VERSION) {
if flags & fuse.O_ANYWRITE != 0 { if flags&fuse.O_ANYWRITE != 0 {
return nil, fuse.EPERM return nil, fuse.EPERM
} }
return fuse.NewReadOnlyFile([]byte(fuse.Version())), fuse.OK return fuse.NewReadOnlyFile([]byte(fuse.Version())), fuse.OK
} }
if path == filepath.Join(_CONFIG, _SCAN_CONFIG) { if path == filepath.Join(_CONFIG, _SCAN_CONFIG) {
if flags & fuse.O_ANYWRITE != 0 { if flags&fuse.O_ANYWRITE != 0 {
me.updateKnownFses() me.updateKnownFses()
} }
return fuse.NewDevNullFile(), fuse.OK return fuse.NewDevNullFile(), fuse.OK
......
...@@ -44,7 +44,7 @@ func setup(t *testing.T) (workdir string, cleanup func()) { ...@@ -44,7 +44,7 @@ func setup(t *testing.T) (workdir string, cleanup func()) {
WriteFile(wd+"/ro/file2", "file2") WriteFile(wd+"/ro/file2", "file2")
fs := NewAutoUnionFs(wd+"/store", testAOpts) fs := NewAutoUnionFs(wd+"/store", testAOpts)
state, conn, err := fuse.MountFileSystem(wd + "/mount", fs, &testAOpts.FileSystemOptions) state, conn, err := fuse.MountFileSystem(wd+"/mount", fs, &testAOpts.FileSystemOptions)
CheckSuccess(err) CheckSuccess(err)
state.Debug = true state.Debug = true
conn.Debug = true conn.Debug = true
...@@ -60,7 +60,7 @@ func TestVersion(t *testing.T) { ...@@ -60,7 +60,7 @@ func TestVersion(t *testing.T) {
wd, clean := setup(t) wd, clean := setup(t)
defer clean() defer clean()
c, err := ioutil.ReadFile(wd+"/mount/status/gounionfs_version") c, err := ioutil.ReadFile(wd + "/mount/status/gounionfs_version")
CheckSuccess(err) CheckSuccess(err)
if len(c) == 0 { if len(c) == 0 {
t.Fatal("No version found.") t.Fatal("No version found.")
...@@ -91,7 +91,7 @@ func TestAutoFsSymlink(t *testing.T) { ...@@ -91,7 +91,7 @@ func TestAutoFsSymlink(t *testing.T) {
time.Sleep(2 * entryTtl * 1e9) time.Sleep(2 * entryTtl * 1e9)
scan := wd + "/mount/config/" + _SCAN_CONFIG scan := wd + "/mount/config/" + _SCAN_CONFIG
err = ioutil.WriteFile(scan, []byte("something"), 0644 ) err = ioutil.WriteFile(scan, []byte("something"), 0644)
if err != nil { if err != nil {
t.Error("error writing:", err) t.Error("error writing:", err)
} }
...@@ -127,12 +127,12 @@ func TestExplicitScan(t *testing.T) { ...@@ -127,12 +127,12 @@ func TestExplicitScan(t *testing.T) {
if err != nil { if err != nil {
t.Error(".scan_config missing:", err) t.Error(".scan_config missing:", err)
} }
err = ioutil.WriteFile(scan, []byte("something"), 0644 ) err = ioutil.WriteFile(scan, []byte("something"), 0644)
if err != nil { if err != nil {
t.Error("error writing:", err) t.Error("error writing:", err)
} }
_, err = os.Lstat(wd + "/mount/backing1") _, err = os.Lstat(wd + "/mount/backing1")
if err != nil { if err != nil {
t.Error("Should have workspace backing1:", err) t.Error("Should have workspace backing1:", err)
......
...@@ -136,10 +136,10 @@ func NewCachingFileSystem(fs fuse.FileSystem, ttlNs int64) *CachingFileSystem { ...@@ -136,10 +136,10 @@ func NewCachingFileSystem(fs fuse.FileSystem, ttlNs int64) *CachingFileSystem {
c.links = NewTimedCache(func(n string) interface{} { return readLink(fs, n) }, ttlNs) c.links = NewTimedCache(func(n string) interface{} { return readLink(fs, n) }, ttlNs)
c.xattr = NewTimedCache(func(n string) interface{} { c.xattr = NewTimedCache(func(n string) interface{} {
return getXAttr(fs, n) return getXAttr(fs, n)
},ttlNs) }, ttlNs)
c.files = NewTimedCache(func(n string) interface{} { c.files = NewTimedCache(func(n string) interface{} {
return openFile(fs, n) return openFile(fs, n)
},ttlNs) }, ttlNs)
return c return c
} }
......
...@@ -16,7 +16,7 @@ func newDirnameMap(fs fuse.FileSystem, dir string) map[string]bool { ...@@ -16,7 +16,7 @@ func newDirnameMap(fs fuse.FileSystem, dir string) map[string]bool {
log.Printf("newDirnameMap(): %v %v", dir, code) log.Printf("newDirnameMap(): %v %v", dir, code)
return nil return nil
} }
result := make(map[string]bool) result := make(map[string]bool)
for e := range stream { for e := range stream {
if e.Mode&fuse.S_IFREG != 0 { if e.Mode&fuse.S_IFREG != 0 {
......
...@@ -570,7 +570,7 @@ func (me *UnionFs) GetAttr(name string) (a *os.FileInfo, s fuse.Status) { ...@@ -570,7 +570,7 @@ func (me *UnionFs) GetAttr(name string) (a *os.FileInfo, s fuse.Status) {
if name == _DROP_CACHE { if name == _DROP_CACHE {
return &os.FileInfo{ return &os.FileInfo{
Mode: fuse.S_IFREG | 0777, Mode: fuse.S_IFREG | 0777,
},fuse.OK }, fuse.OK
} }
if name == me.options.DeletionDirName { if name == me.options.DeletionDirName {
return nil, fuse.ENOENT return nil, fuse.ENOENT
......
...@@ -48,7 +48,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) { ...@@ -48,7 +48,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
NegativeTimeout: entryTtl, NegativeTimeout: entryTtl,
} }
state, _, err := fuse.MountFileSystem(wd + "/mount", ufs, opts) state, _, err := fuse.MountFileSystem(wd+"/mount", ufs, opts)
CheckSuccess(err) CheckSuccess(err)
state.Debug = true state.Debug = true
go state.Loop(false) go state.Loop(false)
...@@ -123,13 +123,13 @@ func TestAutocreateDeletionDir(t *testing.T) { ...@@ -123,13 +123,13 @@ func TestAutocreateDeletionDir(t *testing.T) {
wd, clean := setupUfs(t) wd, clean := setupUfs(t)
defer clean() defer clean()
err := os.Remove(wd+"/rw/DELETIONS") err := os.Remove(wd + "/rw/DELETIONS")
CheckSuccess(err) CheckSuccess(err)
err = os.Mkdir(wd+"/mount/dir", 0755) err = os.Mkdir(wd+"/mount/dir", 0755)
CheckSuccess(err) CheckSuccess(err)
_, err = ioutil.ReadDir(wd+"/mount/dir") _, err = ioutil.ReadDir(wd + "/mount/dir")
CheckSuccess(err) CheckSuccess(err)
} }
...@@ -498,7 +498,7 @@ func TestRemoveAll(t *testing.T) { ...@@ -498,7 +498,7 @@ func TestRemoveAll(t *testing.T) {
wd, clean := setupUfs(t) wd, clean := setupUfs(t)
defer clean() defer clean()
err := os.Mkdir(wd + "/ro/dir", 0755) err := os.Mkdir(wd+"/ro/dir", 0755)
CheckSuccess(err) CheckSuccess(err)
contents := "hello" contents := "hello"
...@@ -506,7 +506,7 @@ func TestRemoveAll(t *testing.T) { ...@@ -506,7 +506,7 @@ func TestRemoveAll(t *testing.T) {
err = ioutil.WriteFile(fn, []byte(contents), 0644) err = ioutil.WriteFile(fn, []byte(contents), 0644)
CheckSuccess(err) CheckSuccess(err)
err = os.RemoveAll(wd+"/mount/dir") err = os.RemoveAll(wd + "/mount/dir")
if err != nil { if err != nil {
t.Error("Should delete all") t.Error("Should delete all")
} }
...@@ -527,7 +527,7 @@ func TestDropCache(t *testing.T) { ...@@ -527,7 +527,7 @@ func TestDropCache(t *testing.T) {
wd, clean := setupUfs(t) wd, clean := setupUfs(t)
defer clean() defer clean()
err := ioutil.WriteFile(wd + "/ro/file", []byte("bla"), 0644) err := ioutil.WriteFile(wd+"/ro/file", []byte("bla"), 0644)
CheckSuccess(err) CheckSuccess(err)
_, err = os.Lstat(wd + "/mount/.drop_cache") _, err = os.Lstat(wd + "/mount/.drop_cache")
...@@ -535,18 +535,18 @@ func TestDropCache(t *testing.T) { ...@@ -535,18 +535,18 @@ func TestDropCache(t *testing.T) {
names, err := Readdirnames(wd + "/mount") names, err := Readdirnames(wd + "/mount")
CheckSuccess(err) CheckSuccess(err)
if len(names) != 1 || names[0] != "file" { if len(names) != 1 || names[0] != "file" {
t.Fatal("unexpected names", names) t.Fatal("unexpected names", names)
} }
err = ioutil.WriteFile(wd + "/ro/file2", []byte("blabla"), 0644) err = ioutil.WriteFile(wd+"/ro/file2", []byte("blabla"), 0644)
names2, err := Readdirnames(wd + "/mount") names2, err := Readdirnames(wd + "/mount")
CheckSuccess(err) CheckSuccess(err)
if len(names2) != len(names) { if len(names2) != len(names) {
t.Fatal("mismatch", names2) t.Fatal("mismatch", names2)
} }
err = ioutil.WriteFile(wd + "/mount/.drop_cache", []byte("does not matter"), 0644) err = ioutil.WriteFile(wd+"/mount/.drop_cache", []byte("does not matter"), 0644)
CheckSuccess(err) CheckSuccess(err)
names2, err = Readdirnames(wd + "/mount") names2, err = Readdirnames(wd + "/mount")
if len(names2) != 2 { if len(names2) != 2 {
...@@ -568,19 +568,19 @@ func TestDisappearing(t *testing.T) { ...@@ -568,19 +568,19 @@ func TestDisappearing(t *testing.T) {
os.Mkdir(wd+"/ro", 0700) os.Mkdir(wd+"/ro", 0700)
fuse.CheckSuccess(err) fuse.CheckSuccess(err)
wrFs := fuse.NewLoopbackFileSystem(wd+"/rw") wrFs := fuse.NewLoopbackFileSystem(wd + "/rw")
var fses []fuse.FileSystem var fses []fuse.FileSystem
fses = append(fses, wrFs) fses = append(fses, wrFs)
fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/ro")) fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/ro"))
ufs := NewUnionFs("testFs", fses, testOpts) ufs := NewUnionFs("testFs", fses, testOpts)
opts := &fuse.FileSystemOptions{ opts := &fuse.FileSystemOptions{
EntryTimeout: entryTtl, EntryTimeout: entryTtl,
AttrTimeout: entryTtl, AttrTimeout: entryTtl,
NegativeTimeout: entryTtl, NegativeTimeout: entryTtl,
} }
state, _, err := fuse.MountFileSystem(wd + "/mount", ufs, opts) state, _, err := fuse.MountFileSystem(wd+"/mount", ufs, opts)
CheckSuccess(err) CheckSuccess(err)
defer state.Unmount() defer state.Unmount()
state.Debug = true state.Debug = true
...@@ -588,23 +588,23 @@ func TestDisappearing(t *testing.T) { ...@@ -588,23 +588,23 @@ func TestDisappearing(t *testing.T) {
log.Println("TestDisappearing2") log.Println("TestDisappearing2")
err = ioutil.WriteFile(wd + "/ro/file", []byte("blabla"), 0644) err = ioutil.WriteFile(wd+"/ro/file", []byte("blabla"), 0644)
CheckSuccess(err) CheckSuccess(err)
err = os.Remove(wd+"/mount/file") err = os.Remove(wd + "/mount/file")
CheckSuccess(err) CheckSuccess(err)
oldRoot := wrFs.Root oldRoot := wrFs.Root
wrFs.Root = "/dev/null" wrFs.Root = "/dev/null"
time.Sleep(1.5*entryTtl*1e9) time.Sleep(1.5 * entryTtl * 1e9)
_, err = ioutil.ReadDir(wd+"/mount") _, err = ioutil.ReadDir(wd + "/mount")
if err == nil { if err == nil {
t.Fatal("Readdir should have failed") t.Fatal("Readdir should have failed")
} }
log.Println("expected readdir failure:", err) log.Println("expected readdir failure:", err)
err = ioutil.WriteFile(wd + "/mount/file2", []byte("blabla"), 0644) err = ioutil.WriteFile(wd+"/mount/file2", []byte("blabla"), 0644)
if err == nil { if err == nil {
t.Fatal("write should have failed") t.Fatal("write should have failed")
} }
...@@ -612,15 +612,14 @@ func TestDisappearing(t *testing.T) { ...@@ -612,15 +612,14 @@ func TestDisappearing(t *testing.T) {
// Restore, and wait for caches to catch up. // Restore, and wait for caches to catch up.
wrFs.Root = oldRoot wrFs.Root = oldRoot
time.Sleep(1.5*entryTtl*1e9) time.Sleep(1.5 * entryTtl * 1e9)
_, err = ioutil.ReadDir(wd+"/mount") _, err = ioutil.ReadDir(wd + "/mount")
if err != nil { if err != nil {
t.Fatal("Readdir should succeed", err) t.Fatal("Readdir should succeed", err)
} }
err = ioutil.WriteFile(wd + "/mount/file2", []byte("blabla"), 0644) err = ioutil.WriteFile(wd+"/mount/file2", []byte("blabla"), 0644)
if err != nil { if err != nil {
t.Fatal("write should succeed", err) t.Fatal("write should succeed", err)
} }
} }
...@@ -21,15 +21,15 @@ func TestMultiZipFs(t *testing.T) { ...@@ -21,15 +21,15 @@ func TestMultiZipFs(t *testing.T) {
fs := NewMultiZipFs() fs := NewMultiZipFs()
mountPoint := fuse.MakeTempDir() mountPoint := fuse.MakeTempDir()
state, _, err := fuse.MountFileSystem(mountPoint, fs, &fuse.FileSystemOptions{ state, _, err := fuse.MountFileSystem(mountPoint, fs, &fuse.FileSystemOptions{
EntryTimeout: testTtl, EntryTimeout: testTtl,
AttrTimeout: testTtl, AttrTimeout: testTtl,
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
}) })
defer os.RemoveAll(mountPoint) defer os.RemoveAll(mountPoint)
CheckSuccess(err) CheckSuccess(err)
defer state.Unmount() defer state.Unmount()
state.Debug = true state.Debug = true
go state.Loop(true) go state.Loop(true)
......
...@@ -73,7 +73,7 @@ func NewTarTree(r io.Reader) *MemTree { ...@@ -73,7 +73,7 @@ func NewTarTree(r io.Reader) *MemTree {
hdr.Name = *longName hdr.Name = *longName
longName = nil longName = nil
} }
comps := strings.Split(filepath.Clean(hdr.Name), "/", -1) comps := strings.Split(filepath.Clean(hdr.Name), "/", -1)
base := "" base := ""
if !strings.HasSuffix(hdr.Name, "/") { if !strings.HasSuffix(hdr.Name, "/") {
......
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