Commit 86b0092e authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use filepath throughout.

parent d2454936
......@@ -14,7 +14,7 @@ import (
"github.com/hanwen/go-fuse/fuse"
"log"
"os"
"path"
"path/filepath"
"sync"
"strings"
)
......@@ -51,7 +51,7 @@ func (me *zipCreateFile) Write(input *fuse.WriteIn, nameBytes []byte) (uint32, f
return 0, fuse.ENOSYS
}
code := me.zfs.Connector.Mount("/"+path.Base(me.Basename), fs)
code := me.zfs.Connector.Mount("/"+filepath.Base(me.Basename), fs)
if code != fuse.OK {
return 0, code
......@@ -142,7 +142,7 @@ func (me *MultiZipFs) GetAttr(name string) (*fuse.Attr, fuse.Status) {
return a, fuse.OK
}
dir, base := path.Split(name)
dir, base := filepath.Split(name)
if dir != "" && dir != CONFIG_PREFIX {
return nil, fuse.ENOENT
}
......@@ -169,7 +169,7 @@ func (me *MultiZipFs) GetAttr(name string) (*fuse.Attr, fuse.Status) {
}
func (me *MultiZipFs) Unlink(name string) (code fuse.Status) {
dir, basename := path.Split(name)
dir, basename := filepath.Split(name)
if dir == CONFIG_PREFIX {
me.lock.Lock()
defer me.lock.Unlock()
......@@ -190,7 +190,7 @@ func (me *MultiZipFs) Open(name string, flags uint32) (file fuse.RawFuseFile, co
return nil, fuse.EPERM
}
dir, basename := path.Split(name)
dir, basename := filepath.Split(name)
if dir == CONFIG_PREFIX {
me.lock.RLock()
defer me.lock.RUnlock()
......@@ -207,7 +207,7 @@ func (me *MultiZipFs) Open(name string, flags uint32) (file fuse.RawFuseFile, co
}
func (me *MultiZipFs) Create(name string, flags uint32, mode uint32) (file fuse.RawFuseFile, code fuse.Status) {
dir, base := path.Split(name)
dir, base := filepath.Split(name)
if dir != CONFIG_PREFIX {
return nil, fuse.EPERM
}
......
......@@ -5,7 +5,7 @@ import (
"fmt"
"log"
"os"
"path"
"path/filepath"
"strings"
"testing"
)
......@@ -33,9 +33,9 @@ func (me *stackFsTestCase) Setup(t *testing.T) {
me.tester = t
me.testDir = fuse.MakeTempDir()
me.origDir1 = path.Join(me.testDir, "orig1")
me.origDir2 = path.Join(me.testDir, "orig2")
me.mountDir = path.Join(me.testDir, "mount")
me.origDir1 = filepath.Join(me.testDir, "orig1")
me.origDir2 = filepath.Join(me.testDir, "orig2")
me.mountDir = filepath.Join(me.testDir, "mount")
os.Mkdir(me.origDir1, 0700)
os.Mkdir(me.origDir2, 0700)
......@@ -107,12 +107,12 @@ func (me *stackFsTestCase) testReaddir() {
func (me *stackFsTestCase) testSubFs() {
fmt.Println("testSubFs... ")
for i := 1; i <= 2; i++ {
// orig := path.Join(me.testDir, fmt.Sprintf("orig%d", i))
mount := path.Join(me.mountDir, fmt.Sprintf("sub%d", i))
// orig := filepath.Join(me.testDir, fmt.Sprintf("orig%d", i))
mount := filepath.Join(me.mountDir, fmt.Sprintf("sub%d", i))
name := "testFile"
mountFile := path.Join(mount, name)
mountFile := filepath.Join(mount, name)
f, err := os.Open(mountFile, os.O_WRONLY, 0)
if err == nil {
......@@ -130,7 +130,7 @@ func (me *stackFsTestCase) testSubFs() {
CheckSuccess(err)
fi, err := os.Lstat(mountFile)
CheckSuccess(err)
CheckSuccess(err)
if fi.Mode&0777 != magicMode {
me.tester.Errorf("Mode %o", fi.Mode)
}
......@@ -166,7 +166,7 @@ func (me *stackFsTestCase) testAddRemove() {
}
conn.Init(new(fuse.InHeader), new(fuse.InitIn))
fi, err := os.Lstat(path.Join(me.mountDir, "third"))
fi, err := os.Lstat(filepath.Join(me.mountDir, "third"))
CheckSuccess(err)
if !fi.IsDirectory() {
......@@ -186,7 +186,7 @@ func (me *stackFsTestCase) testAddRemove() {
}
dir.Close()
_, err = os.Open(path.Join(me.mountDir, "third"), os.O_RDONLY, 0)
_, err = os.Open(filepath.Join(me.mountDir, "third"), os.O_RDONLY, 0)
if err == nil {
me.tester.Errorf("expect enoent %v", err)
}
......
......@@ -6,7 +6,7 @@ import (
"fmt"
"os"
"strings"
"path"
"path/filepath"
"log"
)
......@@ -44,7 +44,7 @@ func (me *ZipDirTree) Lookup(name string) (*ZipDirTree, *zip.File) {
return me, nil
}
parent := me
comps := strings.Split(path.Clean(name), "/", -1)
comps := strings.Split(filepath.Clean(name), "/", -1)
for _, c := range comps[:len(comps)-1] {
parent = parent.subdirs[c]
if parent == nil {
......@@ -82,7 +82,7 @@ func zipFilesToTree(files []*zip.File) *ZipDirTree {
t := NewZipDirTree()
for _, f := range files {
parent := t
comps := strings.Split(path.Clean(f.Name), "/", -1)
comps := strings.Split(filepath.Clean(f.Name), "/", -1)
base := ""
// Ugh - zip files have directories separate.
......
......@@ -16,7 +16,7 @@ import (
const (
// bufSize should be a power of two to minimize lossage in
// BufferPool.
bufSize = (1 << 16)
bufSize = (1 << 18)
maxRead = bufSize - PAGESIZE
)
......
......@@ -7,7 +7,7 @@ package fuse
import (
"fmt"
"os"
"path"
"path/filepath"
"syscall"
)
......@@ -27,7 +27,7 @@ func NewLoopbackFileSystem(root string) (out *LoopbackFileSystem) {
}
func (me *LoopbackFileSystem) GetPath(relPath string) string {
return path.Join(me.root, relPath)
return filepath.Join(me.root, relPath)
}
func (me *LoopbackFileSystem) GetAttr(name string) (*Attr, Status) {
......
......@@ -5,7 +5,7 @@ import (
"fmt"
"log"
"os"
"path"
"path/filepath"
"strings"
"testing"
"syscall"
......@@ -46,12 +46,12 @@ func (me *testCase) Setup(t *testing.T) {
me.origDir = MakeTempDir()
me.mountPoint = MakeTempDir()
me.mountFile = path.Join(me.mountPoint, name)
me.mountSubdir = path.Join(me.mountPoint, subdir)
me.mountSubfile = path.Join(me.mountSubdir, "subfile")
me.origFile = path.Join(me.origDir, name)
me.origSubdir = path.Join(me.origDir, subdir)
me.origSubfile = path.Join(me.origSubdir, "subfile")
me.mountFile = filepath.Join(me.mountPoint, name)
me.mountSubdir = filepath.Join(me.mountPoint, subdir)
me.mountSubfile = filepath.Join(me.mountSubdir, "subfile")
me.origFile = filepath.Join(me.origDir, name)
me.origSubdir = filepath.Join(me.origDir, subdir)
me.origSubfile = filepath.Join(me.origSubdir, "subfile")
pfs := NewLoopbackFileSystem(me.origDir)
me.connector = NewPathFileSystemConnector(pfs)
......@@ -108,7 +108,7 @@ func (me *testCase) writeOrigFile() {
// Tests.
func (me *testCase) testOpenUnreadable() {
_, err := os.Open(path.Join(me.mountPoint, "doesnotexist"), os.O_RDONLY, 0)
_, err := os.Open(filepath.Join(me.mountPoint, "doesnotexist"), os.O_RDONLY, 0)
if err == nil {
me.tester.Errorf("open non-existent should raise error")
}
......@@ -241,13 +241,13 @@ func (me *testCase) testSymlink() {
linkFile := "symlink-file"
orig := "hello.txt"
err := os.Symlink(orig, path.Join(me.mountPoint, linkFile))
defer os.Remove(path.Join(me.mountPoint, linkFile))
err := os.Symlink(orig, filepath.Join(me.mountPoint, linkFile))
defer os.Remove(filepath.Join(me.mountPoint, linkFile))
defer me.removeMountFile()
CheckSuccess(err)
origLink := path.Join(me.origDir, linkFile)
origLink := filepath.Join(me.origDir, linkFile)
fi, err := os.Lstat(origLink)
CheckSuccess(err)
......@@ -256,7 +256,7 @@ func (me *testCase) testSymlink() {
return
}
read, err := os.Readlink(path.Join(me.mountPoint, linkFile))
read, err := os.Readlink(filepath.Join(me.mountPoint, linkFile))
CheckSuccess(err)
if read != orig {
......@@ -368,7 +368,7 @@ func (me *testCase) testFSync() {
func (me *testCase) testLargeRead() {
me.tester.Log("Testing large read.")
name := path.Join(me.origDir, "large")
name := filepath.Join(me.origDir, "large")
f, err := os.Open(name, os.O_WRONLY|os.O_CREATE, 0777)
CheckSuccess(err)
......@@ -387,7 +387,7 @@ func (me *testCase) testLargeRead() {
CheckSuccess(err)
// Read in one go.
g, err := os.Open(path.Join(me.mountPoint, "large"), os.O_RDONLY, 0)
g, err := os.Open(filepath.Join(me.mountPoint, "large"), os.O_RDONLY, 0)
CheckSuccess(err)
readSlice := make([]byte, len(slice))
m, err := g.Read(readSlice)
......@@ -405,7 +405,7 @@ func (me *testCase) testLargeRead() {
g.Close()
// Read in chunks
g, err = os.Open(path.Join(me.mountPoint, "large"), os.O_RDONLY, 0)
g, err = os.Open(filepath.Join(me.mountPoint, "large"), os.O_RDONLY, 0)
CheckSuccess(err)
readSlice = make([]byte, 4096)
total := 0
......@@ -444,7 +444,7 @@ func (me *testCase) testLargeDirRead() {
names := make([]string, created)
subdir := path.Join(me.origDir, "readdirSubdir")
subdir := filepath.Join(me.origDir, "readdirSubdir")
os.Mkdir(subdir, 0700)
longname := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
......@@ -453,7 +453,7 @@ func (me *testCase) testLargeDirRead() {
// Should vary file name length.
base := fmt.Sprintf("file%d%s", i,
randomLengthString(len(longname)))
name := path.Join(subdir, base)
name := filepath.Join(subdir, base)
nameSet[base] = true
......@@ -465,7 +465,7 @@ func (me *testCase) testLargeDirRead() {
names[i] = name
}
dir, err := os.Open(path.Join(me.mountPoint, "readdirSubdir"), os.O_RDONLY, 0)
dir, err := os.Open(filepath.Join(me.mountPoint, "readdirSubdir"), os.O_RDONLY, 0)
CheckSuccess(err)
// Chunked read.
total := 0
......@@ -524,7 +524,7 @@ func TestRecursiveMount(t *testing.T) {
ts := new(testCase)
ts.Setup(t)
f, err := os.Open(path.Join(ts.mountPoint, "hello.txt"),
f, err := os.Open(filepath.Join(ts.mountPoint, "hello.txt"),
os.O_WRONLY|os.O_CREATE, 0777)
CheckSuccess(err)
......@@ -537,7 +537,7 @@ func TestRecursiveMount(t *testing.T) {
t.Error("expect EINVAL", code)
}
submnt := path.Join(ts.mountPoint, "mnt")
submnt := filepath.Join(ts.mountPoint, "mnt")
err = os.Mkdir(submnt, 0777)
CheckSuccess(err)
code = ts.connector.Mount("/mnt", pfs2)
......@@ -547,10 +547,10 @@ func TestRecursiveMount(t *testing.T) {
_, err = os.Lstat(submnt)
CheckSuccess(err)
_, err = os.Lstat(path.Join(submnt, "hello.txt"))
_, err = os.Lstat(filepath.Join(submnt, "hello.txt"))
CheckSuccess(err)
f, err = os.Open(path.Join(submnt, "hello.txt"), os.O_RDONLY, 0)
f, err = os.Open(filepath.Join(submnt, "hello.txt"), os.O_RDONLY, 0)
CheckSuccess(err)
code = ts.connector.Unmount("/mnt")
if code != EBUSY {
......
......@@ -9,7 +9,7 @@ import (
"os"
"time"
"fmt"
"path"
"path/filepath"
"math"
"regexp"
"syscall"
......@@ -24,7 +24,7 @@ func MakeTempDir() string {
number := source.Int63() & 0xffff
name := fmt.Sprintf("tmp%d", number)
fullName := path.Join(os.TempDir(), name)
fullName := filepath.Join(os.TempDir(), name)
err := os.Mkdir(fullName, 0700)
if err != nil {
panic("Mkdir() should always succeed: " + fullName)
......@@ -49,7 +49,7 @@ func OsErrorToFuseError(err os.Error) Status {
if ok {
return OsErrorToFuseError(asPathErr.Error)
}
// Should not happen. Should we log an error somewhere?
return ENOSYS
}
......@@ -270,7 +270,6 @@ func Writev(fd int, packet [][]byte) (n int, err os.Error) {
if errno != 0 {
err = os.NewSyscallError("writev", errno)
return
}
return
}
......
......@@ -4,7 +4,7 @@ package fuse
import (
"fmt"
"os"
"path"
"path/filepath"
"syscall"
"unsafe"
)
......@@ -42,13 +42,13 @@ func mount(mountPoint string) (f *os.File, finalMountPoint string, err os.Error)
defer local.Close()
defer remote.Close()
mountPoint = path.Clean(mountPoint)
if !path.IsAbs(mountPoint) {
mountPoint = filepath.Clean(mountPoint)
if !filepath.IsAbs(mountPoint) {
cwd, err := os.Getwd()
if err != nil {
return
}
mountPoint = path.Clean(path.Join(cwd, mountPoint))
mountPoint = filepath.Clean(filepath.Join(cwd, mountPoint))
}
proc, err := os.StartProcess("/bin/fusermount",
[]string{"/bin/fusermount", mountPoint},
......@@ -73,7 +73,7 @@ func mount(mountPoint string) (f *os.File, finalMountPoint string, err os.Error)
}
func unmount(mountPoint string) (err os.Error) {
dir, _ := path.Split(mountPoint)
dir, _ := filepath.Split(mountPoint)
proc, err := os.StartProcess("/bin/fusermount",
[]string{"/bin/fusermount", "-u", mountPoint},
nil,
......
......@@ -4,7 +4,7 @@ import (
"bytes"
"fmt"
"log"
"path"
"path/filepath"
"strings"
"sync"
)
......@@ -15,7 +15,7 @@ type mountData struct {
// Protects the variables below.
mutex sync.RWMutex
// If yes, we are looking to unmount the mounted fs.
unmountPending bool
......@@ -277,7 +277,7 @@ func (me *PathFileSystemConnector) unlinkUpdate(nodeid uint64, name string) {
// Walk the file system starting from the root.
func (me *PathFileSystemConnector) findInode(fullPath string) *inodeData {
fullPath = strings.TrimLeft(path.Clean(fullPath), "/")
fullPath = strings.TrimLeft(filepath.Clean(fullPath), "/")
comps := strings.Split(fullPath, "/", -1)
me.lock.RLock()
......@@ -334,7 +334,7 @@ func (me *PathFileSystemConnector) Mount(mountPoint string, fs PathFilesystem) S
var node *inodeData
if mountPoint != "/" {
dirParent, base := path.Split(mountPoint)
dirParent, base := filepath.Split(mountPoint)
dirParentNode := me.findInode(dirParent)
// Make sure we know the mount point.
......@@ -393,7 +393,7 @@ func (me *PathFileSystemConnector) Unmount(path string) Status {
if me.Debug {
log.Println("Unmount: ", mount)
}
if node.RefCount > 0 {
mount.fs.Unmount()
mount.unmountPending = true
......@@ -435,7 +435,7 @@ func (me *PathFileSystemConnector) internalLookup(nodeid uint64, name string, lo
if mount == nil {
return NegativeEntry(me.options.NegativeTimeout), OK
}
fullPath = path.Join(fullPath, name)
fullPath = filepath.Join(fullPath, name)
attr, err := mount.fs.GetAttr(fullPath)
......@@ -570,7 +570,7 @@ func (me *PathFileSystemConnector) Mknod(header *InHeader, input *MknodIn, name
if mount == nil {
return nil, ENOENT
}
fullPath = path.Join(fullPath, name)
fullPath = filepath.Join(fullPath, name)
err := mount.fs.Mknod(fullPath, input.Mode, uint32(input.Rdev))
if err != OK {
return nil, err
......@@ -583,7 +583,7 @@ func (me *PathFileSystemConnector) Mkdir(header *InHeader, input *MkdirIn, name
if mount == nil {
return nil, ENOENT
}
err := mount.fs.Mkdir(path.Join(fullPath, name), input.Mode)
err := mount.fs.Mkdir(filepath.Join(fullPath, name), input.Mode)
if err != OK {
return nil, err
}
......@@ -596,7 +596,7 @@ func (me *PathFileSystemConnector) Unlink(header *InHeader, name string) (code S
if mount == nil {
return ENOENT
}
code = mount.fs.Unlink(path.Join(fullPath, name))
code = mount.fs.Unlink(filepath.Join(fullPath, name))
// Like fuse.c, we update our internal tables.
me.unlinkUpdate(header.NodeId, name)
......@@ -609,7 +609,7 @@ func (me *PathFileSystemConnector) Rmdir(header *InHeader, name string) (code St
if mount == nil {
return ENOENT
}
code = mount.fs.Rmdir(path.Join(fullPath, name))
code = mount.fs.Rmdir(filepath.Join(fullPath, name))
me.unlinkUpdate(header.NodeId, name)
return code
}
......@@ -619,7 +619,7 @@ func (me *PathFileSystemConnector) Symlink(header *InHeader, pointedTo string, l
if mount == nil {
return nil, ENOENT
}
err := mount.fs.Symlink(pointedTo, path.Join(fullPath, linkName))
err := mount.fs.Symlink(pointedTo, filepath.Join(fullPath, linkName))
if err != OK {
return nil, err
}
......@@ -638,8 +638,8 @@ func (me *PathFileSystemConnector) Rename(header *InHeader, input *RenameIn, old
return EXDEV
}
oldPath = path.Join(oldPath, oldName)
newPath = path.Join(newPath, newName)
oldPath = filepath.Join(oldPath, oldName)
newPath = filepath.Join(newPath, newName)
code = mount.fs.Rename(oldPath, newPath)
if code != OK {
return
......@@ -666,7 +666,7 @@ func (me *PathFileSystemConnector) Link(header *InHeader, input *LinkIn, filenam
if mount != newMount {
return nil, EXDEV
}
newName = path.Join(newName, filename)
newName = filepath.Join(newName, filename)
err := mount.fs.Link(orig, newName)
if err != OK {
......@@ -689,7 +689,7 @@ func (me *PathFileSystemConnector) Create(header *InHeader, input *CreateIn, nam
if mount == nil {
return 0, nil, nil, ENOENT
}
fullPath := path.Join(directory, name)
fullPath := filepath.Join(directory, name)
f, err := mount.fs.Create(fullPath, uint32(input.Flags), input.Mode)
if err != OK {
......
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