Share unmount code.
parent
53d662ca0b
commit
dff6fe8c82
|
@ -18,8 +18,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/googlecloudplatform/gcsfuse/timeutil"
|
||||
|
@ -124,27 +122,10 @@ func (t *SampleTest) destroy() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Unmount the file system. Try again on "resource busy" errors.
|
||||
delay := 10 * time.Millisecond
|
||||
for {
|
||||
err = t.mfs.Unmount()
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if strings.Contains(err.Error(), "resource busy") {
|
||||
log.Println("Resource busy error while unmounting; trying again")
|
||||
time.Sleep(delay)
|
||||
delay = time.Duration(1.3 * float64(delay))
|
||||
continue
|
||||
}
|
||||
|
||||
err = fmt.Errorf("MountedFileSystem.Unmount: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = t.mfs.Join(t.Ctx); err != nil {
|
||||
err = fmt.Errorf("MountedFileSystem.Join: %v", err)
|
||||
// Unmount the file system.
|
||||
err = unmount(t.Dir)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("unmount: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -18,14 +18,10 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/jacobsa/bazilfuse"
|
||||
"github.com/jacobsa/ogletest"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
@ -182,22 +178,10 @@ func (t *SubprocessTest) destroy() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Unmount the file system. Try again on "resource busy" errors.
|
||||
delay := 10 * time.Millisecond
|
||||
for {
|
||||
err = bazilfuse.Unmount(t.Dir)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if strings.Contains(err.Error(), "resource busy") {
|
||||
log.Println("Resource busy error while unmounting; trying again")
|
||||
time.Sleep(delay)
|
||||
delay = time.Duration(1.3 * float64(delay))
|
||||
continue
|
||||
}
|
||||
|
||||
err = fmt.Errorf("Unmount: %v", err)
|
||||
// Unmount the file system.
|
||||
err = unmount(t.Dir)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("unmount: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package samples
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jacobsa/bazilfuse"
|
||||
)
|
||||
|
||||
// Unmount the file system mounted at the supplied directory. Try again on
|
||||
// "resource busy" errors, which happen from time to time on OS X (due to weird
|
||||
// requests from the Finder) and when tests don't or can't synchronize all
|
||||
// events.
|
||||
func unmount(dir string) (err error) {
|
||||
delay := 10 * time.Millisecond
|
||||
for {
|
||||
err = bazilfuse.Unmount(dir)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if strings.Contains(err.Error(), "resource busy") {
|
||||
log.Println("Resource busy error while unmounting; trying again")
|
||||
time.Sleep(delay)
|
||||
delay = time.Duration(1.3 * float64(delay))
|
||||
continue
|
||||
}
|
||||
|
||||
err = fmt.Errorf("Unmount: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue