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

Updates for weekly-2012.02.22

parent cb10e93d
...@@ -32,9 +32,19 @@ func (code Status) Ok() bool { ...@@ -32,9 +32,19 @@ func (code Status) Ok() bool {
// Convert error back to Errno based errors. // Convert error back to Errno based errors.
func ToStatus(err error) Status { func ToStatus(err error) Status {
if err == nil { switch err {
case nil:
return OK return OK
case os.ErrPermission:
return EPERM
case os.ErrExist:
return Status(syscall.EEXIST)
case os.ErrNotExist:
return ENOENT
case os.ErrInvalid:
return EINVAL
} }
switch t := err.(type) { switch t := err.(type) {
case syscall.Errno: case syscall.Errno:
return Status(t) return Status(t)
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
) )
func TestToStatus(t *testing.T) { func TestToStatus(t *testing.T) {
errNo := ToStatus(os.EPERM) errNo := ToStatus(os.ErrPermission)
if errNo != EPERM { if errNo != EPERM {
t.Errorf("Wrong conversion %v != %v", errNo, syscall.EPERM) t.Errorf("Wrong conversion %v != %v", errNo, syscall.EPERM)
} }
......
...@@ -47,11 +47,9 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin ...@@ -47,11 +47,9 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin
cmd := []string{fusermountBinary, mountPoint} cmd := []string{fusermountBinary, mountPoint}
if options != "" { if options != "" {
log.Printf("o %q", options)
cmd = append(cmd, "-o") cmd = append(cmd, "-o")
cmd = append(cmd, options) cmd = append(cmd, options)
} }
proc, err := os.StartProcess(fusermountBinary, proc, err := os.StartProcess(fusermountBinary,
cmd, cmd,
&os.ProcAttr{ &os.ProcAttr{
...@@ -61,12 +59,13 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin ...@@ -61,12 +59,13 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin
if err != nil { if err != nil {
return return
} }
w, err := os.Wait(proc.Pid, 0)
w, err := proc.Wait()
if err != nil { if err != nil {
return return
} }
if w.ExitStatus() != 0 { if !w.Success() {
err = fmt.Errorf("fusermount exited with code %d\n", w.ExitStatus()) err = fmt.Errorf("fusermount exited with code %v\n", w.Sys())
return return
} }
...@@ -83,9 +82,9 @@ func privilegedUnmount(mountPoint string) error { ...@@ -83,9 +82,9 @@ func privilegedUnmount(mountPoint string) error {
if err != nil { if err != nil {
return err return err
} }
w, err := os.Wait(proc.Pid, 0) w, err := proc.Wait()
if w.ExitStatus() != 0 { if !w.Success() {
return fmt.Errorf("umount exited with code %d\n", w.ExitStatus()) return fmt.Errorf("umount exited with code %v\n", w.Sys())
} }
return err return err
} }
...@@ -101,12 +100,12 @@ func unmount(mountPoint string) (err error) { ...@@ -101,12 +100,12 @@ func unmount(mountPoint string) (err error) {
if err != nil { if err != nil {
return return
} }
w, err := os.Wait(proc.Pid, 0) w, err := proc.Wait()
if err != nil { if err != nil {
return return
} }
if w.ExitStatus() != 0 { if !w.Success() {
return fmt.Errorf("fusermount -u exited with code %d\n", w.ExitStatus()) return fmt.Errorf("fusermount -u exited with code %v\n", w.Sys())
} }
return return
} }
......
...@@ -111,6 +111,7 @@ func (me *MountState) Unmount() (err error) { ...@@ -111,6 +111,7 @@ func (me *MountState) Unmount() (err error) {
delay = 2*delay + 5*time.Millisecond delay = 2*delay + 5*time.Millisecond
time.Sleep(delay) time.Sleep(delay)
} }
me.mountPoint = ""
return err return err
} }
...@@ -180,7 +181,6 @@ func (me *MountState) Loop() { ...@@ -180,7 +181,6 @@ func (me *MountState) Loop() {
me.loop() me.loop()
me.mountFile.Close() me.mountFile.Close()
me.mountFile = nil me.mountFile = nil
me.mountPoint = ""
} }
func (me *MountState) loop() { func (me *MountState) loop() {
......
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