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

Update for weekly.2011-11-02

parent 3881211d
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"bufio" "bufio"
"flag" "flag"
"github.com/hanwen/go-fuse/benchmark" "github.com/hanwen/go-fuse/benchmark"
"log"
"os" "os"
"runtime" "runtime"
) )
...@@ -24,7 +25,7 @@ func main() { ...@@ -24,7 +25,7 @@ func main() {
filename := flag.Args()[0] filename := flag.Args()[0]
f, err := os.Open(filename) f, err := os.Open(filename)
if err != nil { if err != nil {
panic("err" + err.String()) log.Panicf("Open: %v", err)
} }
reader := bufio.NewReader(f) reader := bufio.NewReader(f)
......
...@@ -163,7 +163,7 @@ func TestGetAttrRace(t *testing.T) { ...@@ -163,7 +163,7 @@ func TestGetAttrRace(t *testing.T) {
n := 100 n := 100
wg.Add(n) wg.Add(n)
var statErr os.Error var statErr error
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
go func() { go func() {
defer wg.Done() defer wg.Done()
......
...@@ -2,6 +2,7 @@ package fuse ...@@ -2,6 +2,7 @@ package fuse
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"syscall" "syscall"
) )
...@@ -97,7 +98,7 @@ func (me *LoopbackFile) Read(input *ReadIn, buffers BufferPool) ([]byte, Status) ...@@ -97,7 +98,7 @@ func (me *LoopbackFile) Read(input *ReadIn, buffers BufferPool) ([]byte, Status)
n, err := me.File.ReadAt(slice, int64(input.Offset)) n, err := me.File.ReadAt(slice, int64(input.Offset))
// TODO - fix Go ndocumentation. // TODO - fix Go ndocumentation.
if err == os.EOF { if err == io.EOF {
err = nil err = nil
} }
return slice[:n], OsErrorToErrno(err) return slice[:n], OsErrorToErrno(err)
......
package fuse package fuse
import ( import "log"
"log"
"os"
)
var _ = log.Println var _ = log.Println
func MountNodeFileSystem(mountpoint string, nodeFs NodeFileSystem, opts *FileSystemOptions) (*MountState, *FileSystemConnector, os.Error) { func MountNodeFileSystem(mountpoint string, nodeFs NodeFileSystem, opts *FileSystemOptions) (*MountState, *FileSystemConnector, error) {
conn := NewFileSystemConnector(nodeFs, opts) conn := NewFileSystemConnector(nodeFs, opts)
mountState := NewMountState(conn) mountState := NewMountState(conn)
err := mountState.Mount(mountpoint, nil) err := mountState.Mount(mountpoint, nil)
...@@ -17,7 +14,7 @@ func MountNodeFileSystem(mountpoint string, nodeFs NodeFileSystem, opts *FileSys ...@@ -17,7 +14,7 @@ func MountNodeFileSystem(mountpoint string, nodeFs NodeFileSystem, opts *FileSys
return mountState, conn, nil return mountState, conn, nil
} }
func MountPathFileSystem(mountpoint string, pathFs FileSystem, opts *FileSystemOptions) (*MountState, *FileSystemConnector, os.Error) { func MountPathFileSystem(mountpoint string, pathFs FileSystem, opts *FileSystemOptions) (*MountState, *FileSystemConnector, error) {
nfs := NewPathNodeFs(pathFs, nil) nfs := NewPathNodeFs(pathFs, nil)
return MountNodeFileSystem(mountpoint, nfs, opts) return MountNodeFileSystem(mountpoint, nfs, opts)
} }
...@@ -6,6 +6,7 @@ package fuse ...@@ -6,6 +6,7 @@ package fuse
import ( import (
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
...@@ -34,7 +35,7 @@ func (me *LoopbackFileSystem) GetPath(relPath string) string { ...@@ -34,7 +35,7 @@ func (me *LoopbackFileSystem) GetPath(relPath string) string {
func (me *LoopbackFileSystem) GetAttr(name string, context *Context) (fi *os.FileInfo, code Status) { func (me *LoopbackFileSystem) GetAttr(name string, context *Context) (fi *os.FileInfo, code Status) {
fullPath := me.GetPath(name) fullPath := me.GetPath(name)
var err os.Error = nil var err error = nil
if name == "" { if name == "" {
// When GetAttr is called for the toplevel directory, we always want // When GetAttr is called for the toplevel directory, we always want
// to look through symlinks. // to look through symlinks.
...@@ -66,7 +67,7 @@ func (me *LoopbackFileSystem) OpenDir(name string, context *Context) (stream cha ...@@ -66,7 +67,7 @@ func (me *LoopbackFileSystem) OpenDir(name string, context *Context) (stream cha
Mode: infos[i].Mode, Mode: infos[i].Mode,
} }
} }
if len(infos) < want || err == os.EOF { if len(infos) < want || err == io.EOF {
break break
} }
if err != nil { if err != nil {
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"exec" "exec"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
...@@ -52,7 +53,7 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -52,7 +53,7 @@ func NewTestCase(t *testing.T) *testCase {
const name string = "hello.txt" const name string = "hello.txt"
const subdir string = "subdir" const subdir string = "subdir"
var err os.Error var err error
me.tmpDir, err = ioutil.TempDir("", "go-fuse") me.tmpDir, err = ioutil.TempDir("", "go-fuse")
CheckSuccess(err) CheckSuccess(err)
me.orig = me.tmpDir + "/orig" me.orig = me.tmpDir + "/orig"
...@@ -567,7 +568,7 @@ func TestLargeRead(t *testing.T) { ...@@ -567,7 +568,7 @@ func TestLargeRead(t *testing.T) {
total := 0 total := 0
for { for {
m, err := g.Read(readSlice) m, err := g.Read(readSlice)
if m == 0 && err == os.EOF { if m == 0 && err == io.EOF {
break break
} }
CheckSuccess(err) CheckSuccess(err)
...@@ -629,7 +630,7 @@ func TestLargeDirRead(t *testing.T) { ...@@ -629,7 +630,7 @@ func TestLargeDirRead(t *testing.T) {
readSet := make(map[string]bool) readSet := make(map[string]bool)
for { for {
namesRead, err := dir.Readdirnames(200) namesRead, err := dir.Readdirnames(200)
if len(namesRead) == 0 || err == os.EOF { if len(namesRead) == 0 || err == io.EOF {
break break
} }
CheckSuccess(err) CheckSuccess(err)
......
...@@ -31,7 +31,7 @@ func (code Status) Ok() bool { ...@@ -31,7 +31,7 @@ func (code Status) Ok() bool {
} }
// Convert os.Error back to Errno based errors. // Convert os.Error back to Errno based errors.
func OsErrorToErrno(err os.Error) Status { func OsErrorToErrno(err error) Status {
if err != nil { if err != nil {
switch t := err.(type) { switch t := err.(type) {
case os.Errno: case os.Errno:
...@@ -39,9 +39,9 @@ func OsErrorToErrno(err os.Error) Status { ...@@ -39,9 +39,9 @@ func OsErrorToErrno(err os.Error) Status {
case *os.SyscallError: case *os.SyscallError:
return Status(t.Errno) return Status(t.Errno)
case *os.PathError: case *os.PathError:
return OsErrorToErrno(t.Error) return OsErrorToErrno(t.Err)
case *os.LinkError: case *os.LinkError:
return OsErrorToErrno(t.Error) return OsErrorToErrno(t.Err)
default: default:
log.Println("can't convert error type:", err) log.Println("can't convert error type:", err)
return ENOSYS return ENOSYS
...@@ -84,7 +84,7 @@ func writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) { ...@@ -84,7 +84,7 @@ func writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) {
return int(n1), int(e1) return int(n1), int(e1)
} }
func Writev(fd int, packet [][]byte) (n int, err os.Error) { func Writev(fd int, packet [][]byte) (n int, err error) {
iovecs := make([]syscall.Iovec, 0, len(packet)) iovecs := make([]syscall.Iovec, 0, len(packet))
for _, v := range packet { for _, v := range packet {
...@@ -113,7 +113,7 @@ func ModeToType(mode uint32) uint32 { ...@@ -113,7 +113,7 @@ func ModeToType(mode uint32) uint32 {
return (mode & 0170000) >> 12 return (mode & 0170000) >> 12
} }
func CheckSuccess(e os.Error) { func CheckSuccess(e error) {
if e != nil { if e != nil {
panic(fmt.Sprintf("Unexpected error: %v", e)) panic(fmt.Sprintf("Unexpected error: %v", e))
} }
......
...@@ -2,6 +2,7 @@ package fuse ...@@ -2,6 +2,7 @@ package fuse
// Written with a look to http://ptspts.blogspot.com/2009/11/fuse-protocol-tutorial-for-linux-26.html // Written with a look to http://ptspts.blogspot.com/2009/11/fuse-protocol-tutorial-for-linux-26.html
import ( import (
"errors"
"exec" "exec"
"fmt" "fmt"
"log" "log"
...@@ -14,7 +15,7 @@ import ( ...@@ -14,7 +15,7 @@ import (
var fusermountBinary string var fusermountBinary string
var umountBinary string var umountBinary string
func Socketpair(network string) (l, r *os.File, err os.Error) { func Socketpair(network string) (l, r *os.File, err error) {
var domain int var domain int
var typ int var typ int
switch network { switch network {
...@@ -38,7 +39,7 @@ func Socketpair(network string) (l, r *os.File, err os.Error) { ...@@ -38,7 +39,7 @@ func Socketpair(network string) (l, r *os.File, err os.Error) {
// Create a FUSE FS on the specified mount point. The returned // Create a FUSE FS on the specified mount point. The returned
// mount point is always absolute. // mount point is always absolute.
func mount(mountPoint string, options string) (f *os.File, finalMountPoint string, err os.Error) { func mount(mountPoint string, options string) (f *os.File, finalMountPoint string, err error) {
local, remote, err := Socketpair("unixgram") local, remote, err := Socketpair("unixgram")
if err != nil { if err != nil {
return return
...@@ -77,7 +78,7 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin ...@@ -77,7 +78,7 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin
return return
} }
if w.ExitStatus() != 0 { if w.ExitStatus() != 0 {
err = os.NewError(fmt.Sprintf("fusermount exited with code %d\n", w.ExitStatus())) err = errors.New(fmt.Sprintf("fusermount exited with code %d\n", w.ExitStatus()))
return return
} }
...@@ -86,7 +87,7 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin ...@@ -86,7 +87,7 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin
return return
} }
func privilegedUnmount(mountPoint string) os.Error { func privilegedUnmount(mountPoint string) error {
dir, _ := filepath.Split(mountPoint) dir, _ := filepath.Split(mountPoint)
proc, err := os.StartProcess(umountBinary, proc, err := os.StartProcess(umountBinary,
[]string{umountBinary, mountPoint}, []string{umountBinary, mountPoint},
...@@ -96,12 +97,12 @@ func privilegedUnmount(mountPoint string) os.Error { ...@@ -96,12 +97,12 @@ func privilegedUnmount(mountPoint string) os.Error {
} }
w, err := os.Wait(proc.Pid, 0) w, err := os.Wait(proc.Pid, 0)
if w.ExitStatus() != 0 { if w.ExitStatus() != 0 {
return os.NewError(fmt.Sprintf("umount exited with code %d\n", w.ExitStatus())) return errors.New(fmt.Sprintf("umount exited with code %d\n", w.ExitStatus()))
} }
return err return err
} }
func unmount(mountPoint string) (err os.Error) { func unmount(mountPoint string) (err error) {
if os.Geteuid() == 0 { if os.Geteuid() == 0 {
return privilegedUnmount(mountPoint) return privilegedUnmount(mountPoint)
} }
...@@ -117,12 +118,12 @@ func unmount(mountPoint string) (err os.Error) { ...@@ -117,12 +118,12 @@ func unmount(mountPoint string) (err os.Error) {
return return
} }
if w.ExitStatus() != 0 { if w.ExitStatus() != 0 {
return os.NewError(fmt.Sprintf("fusermount -u exited with code %d\n", w.ExitStatus())) return errors.New(fmt.Sprintf("fusermount -u exited with code %d\n", w.ExitStatus()))
} }
return return
} }
func getConnection(local *os.File) (f *os.File, err os.Error) { func getConnection(local *os.File) (f *os.File, err error) {
var data [4]byte var data [4]byte
control := make([]byte, 4*256) control := make([]byte, 4*256)
...@@ -138,15 +139,15 @@ func getConnection(local *os.File) (f *os.File, err os.Error) { ...@@ -138,15 +139,15 @@ func getConnection(local *os.File) (f *os.File, err os.Error) {
fd := *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&control[0])) + syscall.SizeofCmsghdr)) fd := *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&control[0])) + syscall.SizeofCmsghdr))
if message.Type != 1 { if message.Type != 1 {
err = os.NewError(fmt.Sprintf("getConnection: recvmsg returned wrong control type: %d", message.Type)) err = errors.New(fmt.Sprintf("getConnection: recvmsg returned wrong control type: %d", message.Type))
return return
} }
if oobn <= syscall.SizeofCmsghdr { if oobn <= syscall.SizeofCmsghdr {
err = os.NewError(fmt.Sprintf("getConnection: too short control message. Length: %d", oobn)) err = errors.New(fmt.Sprintf("getConnection: too short control message. Length: %d", oobn))
return return
} }
if fd < 0 { if fd < 0 {
err = os.NewError(fmt.Sprintf("getConnection: fd < 0: %d", fd)) err = errors.New(fmt.Sprintf("getConnection: fd < 0: %d", fd))
return return
} }
f = os.NewFile(int(fd), "<fuseConnection>") f = os.NewFile(int(fd), "<fuseConnection>")
...@@ -154,7 +155,7 @@ func getConnection(local *os.File) (f *os.File, err os.Error) { ...@@ -154,7 +155,7 @@ func getConnection(local *os.File) (f *os.File, err os.Error) {
} }
func init() { func init() {
var err os.Error var err error
fusermountBinary, err = exec.LookPath("fusermount") fusermountBinary, err = exec.LookPath("fusermount")
if err != nil { if err != nil {
log.Fatal("Could not find fusermount binary: %v", err) log.Fatal("Could not find fusermount binary: %v", err)
......
...@@ -48,7 +48,7 @@ func (me *MountState) MountPoint() string { ...@@ -48,7 +48,7 @@ func (me *MountState) MountPoint() string {
} }
// Mount filesystem on mountPoint. // Mount filesystem on mountPoint.
func (me *MountState) Mount(mountPoint string, opts *MountOptions) os.Error { func (me *MountState) Mount(mountPoint string, opts *MountOptions) error {
if opts == nil { if opts == nil {
opts = &MountOptions{ opts = &MountOptions{
MaxBackground: _DEFAULT_BACKGROUND_TASKS, MaxBackground: _DEFAULT_BACKGROUND_TASKS,
...@@ -87,7 +87,7 @@ func (me *MountState) SetRecordStatistics(record bool) { ...@@ -87,7 +87,7 @@ func (me *MountState) SetRecordStatistics(record bool) {
} }
} }
func (me *MountState) Unmount() os.Error { func (me *MountState) Unmount() error {
// Todo: flush/release all files/dirs? // Todo: flush/release all files/dirs?
err := unmount(me.mountPoint) err := unmount(me.mountPoint)
if err == nil { if err == nil {
...@@ -125,7 +125,7 @@ func (me *MountState) newRequest() *request { ...@@ -125,7 +125,7 @@ func (me *MountState) newRequest() *request {
} }
} }
func (me *MountState) readRequest(req *request) os.Error { func (me *MountState) readRequest(req *request) error {
n, err := me.mountFile.Read(req.inputBuf) n, err := me.mountFile.Read(req.inputBuf)
// If we start timing before the read, we may take into // If we start timing before the read, we may take into
// account waiting for input into the timing. // account waiting for input into the timing.
...@@ -246,7 +246,7 @@ func (me *MountState) write(req *request) Status { ...@@ -246,7 +246,7 @@ func (me *MountState) write(req *request) Status {
return OK return OK
} }
var err os.Error var err error
if req.flatData == nil { if req.flatData == nil {
_, err = me.mountFile.Write(req.outHeaderBytes) _, err = me.mountFile.Write(req.outHeaderBytes)
} else { } else {
......
...@@ -43,7 +43,7 @@ type NotifyTest struct { ...@@ -43,7 +43,7 @@ type NotifyTest struct {
func NewNotifyTest() *NotifyTest { func NewNotifyTest() *NotifyTest {
me := &NotifyTest{} me := &NotifyTest{}
me.fs = &NotifyFs{} me.fs = &NotifyFs{}
var err os.Error var err error
me.dir, err = ioutil.TempDir("", "go-fuse") me.dir, err = ioutil.TempDir("", "go-fuse")
CheckSuccess(err) CheckSuccess(err)
entryTtl := 0.1 entryTtl := 0.1
......
...@@ -163,7 +163,7 @@ func (me *AutoUnionFs) getRoots(path string) []string { ...@@ -163,7 +163,7 @@ func (me *AutoUnionFs) getRoots(path string) []string {
return nil return nil
} }
func (me *AutoUnionFs) visit(path string, fi *os.FileInfo, err os.Error) os.Error { func (me *AutoUnionFs) visit(path string, fi *os.FileInfo, err error) error {
if fi.IsDirectory() { if fi.IsDirectory() {
roots := me.getRoots(path) roots := me.getRoots(path)
if roots != nil { if roots != nil {
...@@ -185,7 +185,7 @@ func (me *AutoUnionFs) updateKnownFses() { ...@@ -185,7 +185,7 @@ func (me *AutoUnionFs) updateKnownFses() {
dir, _ = os.Stat(path) dir, _ = os.Stat(path)
me.visit(path, dir, nil) me.visit(path, dir, nil)
filepath.Walk(path, filepath.Walk(path,
func(path string, fi *os.FileInfo, err os.Error) os.Error { func(path string, fi *os.FileInfo, err error) error {
return me.visit(path, fi, err) return me.visit(path, fi, err)
}) })
} }
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"os" "os"
) )
func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions, roCaching bool) (*UnionFs, os.Error) { func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions, roCaching bool) (*UnionFs, error) {
fses := make([]fuse.FileSystem, 0) fses := make([]fuse.FileSystem, 0)
for i, r := range roots { for i, r := range roots {
var fs fuse.FileSystem var fs fuse.FileSystem
......
...@@ -30,7 +30,7 @@ var testOpts = UnionFsOptions{ ...@@ -30,7 +30,7 @@ var testOpts = UnionFsOptions{
func freezeRo(dir string) { func freezeRo(dir string) {
err := filepath.Walk( err := filepath.Walk(
dir, dir,
func(path string, fi *os.FileInfo, err os.Error) os.Error { func(path string, fi *os.FileInfo, err error) error {
return os.Chmod(path, (fi.Mode&0777)&^0222) return os.Chmod(path, (fi.Mode&0777)&^0222)
}) })
CheckSuccess(err) CheckSuccess(err)
...@@ -772,7 +772,7 @@ func TestUnionFsRmRf(t *testing.T) { ...@@ -772,7 +772,7 @@ func TestUnionFsRmRf(t *testing.T) {
} }
} }
func Readdirnames(dir string) ([]string, os.Error) { func Readdirnames(dir string) ([]string, error) {
f, err := os.Open(dir) f, err := os.Open(dir)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -51,7 +51,7 @@ func NewTarTree(r io.Reader) map[string]MemFile { ...@@ -51,7 +51,7 @@ func NewTarTree(r io.Reader) map[string]MemFile {
var longName *string var longName *string
for { for {
hdr, err := tr.Next() hdr, err := tr.Next()
if err == os.EOF { if err == io.EOF {
// end of tar archive // end of tar archive
break break
} }
...@@ -87,7 +87,7 @@ func NewTarTree(r io.Reader) map[string]MemFile { ...@@ -87,7 +87,7 @@ func NewTarTree(r io.Reader) map[string]MemFile {
return files return files
} }
func NewTarCompressedTree(name string, format string) (map[string]MemFile, os.Error) { func NewTarCompressedTree(name string, format string) (map[string]MemFile, error) {
f, err := os.Open(name) f, err := os.Open(name)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -3,6 +3,7 @@ package zipfs ...@@ -3,6 +3,7 @@ package zipfs
import ( import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"errors"
"fmt" "fmt"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"io" "io"
...@@ -42,7 +43,7 @@ func (me *ZipFile) Data() []byte { ...@@ -42,7 +43,7 @@ func (me *ZipFile) Data() []byte {
} }
// NewZipTree creates a new file-system for the zip file named name. // NewZipTree creates a new file-system for the zip file named name.
func NewZipTree(name string) (map[string]MemFile, os.Error) { func NewZipTree(name string) (map[string]MemFile, error) {
r, err := zip.OpenReader(name) r, err := zip.OpenReader(name)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -61,7 +62,7 @@ func NewZipTree(name string) (map[string]MemFile, os.Error) { ...@@ -61,7 +62,7 @@ func NewZipTree(name string) (map[string]MemFile, os.Error) {
return out, nil return out, nil
} }
func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err os.Error) { func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err error) {
mfs = &MemTreeFs{} mfs = &MemTreeFs{}
if strings.HasSuffix(name, ".zip") { if strings.HasSuffix(name, ".zip") {
mfs.files, err = NewZipTree(name) mfs.files, err = NewZipTree(name)
...@@ -84,7 +85,7 @@ func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err os.Error) { ...@@ -84,7 +85,7 @@ func NewArchiveFileSystem(name string) (mfs *MemTreeFs, err os.Error) {
} }
if mfs.files == nil { if mfs.files == nil {
return nil, os.NewError(fmt.Sprintf("Unknown type for %v", name)) return nil, errors.New(fmt.Sprintf("Unknown type for %v", name))
} }
return mfs, nil return mfs, nil
......
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