forked from TrueCloudLab/restic
Add waitForMount for OSX
This commit is contained in:
parent
fe6f1c01f3
commit
eadfcd3f9e
1 changed files with 37 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -17,6 +18,41 @@ import (
|
||||||
. "github.com/restic/restic/test"
|
. "github.com/restic/restic/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mountWait = 20
|
||||||
|
mountSleep = 100 * time.Millisecond
|
||||||
|
mountTestSubdir = "snapshots"
|
||||||
|
)
|
||||||
|
|
||||||
|
// waitForMount blocks (max mountWait * mountSleep) until the subdir
|
||||||
|
// "snapshots" appears in the dir.
|
||||||
|
func waitForMount(dir string) error {
|
||||||
|
for i := 0; i < mountWait; i++ {
|
||||||
|
f, err := os.Open(dir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
names, err := f.Readdirnames(-1)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = f.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, name := range names {
|
||||||
|
if name == mountTestSubdir {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(mountSleep)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("subdir %q of dir %s never appeared", mountTestSubdir, dir)
|
||||||
|
}
|
||||||
func TestMount(t *testing.T) {
|
func TestMount(t *testing.T) {
|
||||||
if !RunFuseTest {
|
if !RunFuseTest {
|
||||||
t.Skip("Skipping fuse tests")
|
t.Skip("Skipping fuse tests")
|
||||||
|
@ -72,6 +108,7 @@ func TestMount(t *testing.T) {
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
OK(t, waitForMount(mountpoint))
|
||||||
|
|
||||||
mountpointDir, err := os.Open(mountpoint)
|
mountpointDir, err := os.Open(mountpoint)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
Loading…
Reference in a new issue