Share unmount code.
parent
53d662ca0b
commit
dff6fe8c82
|
@ -18,8 +18,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/googlecloudplatform/gcsfuse/timeutil"
|
"github.com/googlecloudplatform/gcsfuse/timeutil"
|
||||||
|
@ -124,27 +122,10 @@ func (t *SampleTest) destroy() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmount the file system. Try again on "resource busy" errors.
|
// Unmount the file system.
|
||||||
delay := 10 * time.Millisecond
|
err = unmount(t.Dir)
|
||||||
for {
|
if err != nil {
|
||||||
err = t.mfs.Unmount()
|
err = fmt.Errorf("unmount: %v", err)
|
||||||
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)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jacobsa/bazilfuse"
|
|
||||||
"github.com/jacobsa/ogletest"
|
"github.com/jacobsa/ogletest"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -182,22 +178,10 @@ func (t *SubprocessTest) destroy() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmount the file system. Try again on "resource busy" errors.
|
// Unmount the file system.
|
||||||
delay := 10 * time.Millisecond
|
err = unmount(t.Dir)
|
||||||
for {
|
if err != nil {
|
||||||
err = bazilfuse.Unmount(t.Dir)
|
err = fmt.Errorf("unmount: %v", err)
|
||||||
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)
|
|
||||||
return
|
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