-
Notifications
You must be signed in to change notification settings - Fork 19
/
overlay.go
46 lines (39 loc) · 996 Bytes
/
overlay.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package testhelpers
import (
"bufio"
"bytes"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
"code.cloudfoundry.org/grootfs/store"
. "github.com/onsi/gomega"
)
func CleanUpOverlayMounts(mountPath string) {
output, err := exec.Command("mount").Output()
Expect(err).NotTo(HaveOccurred())
buffer := bytes.NewBuffer(output)
scanner := bufio.NewScanner(buffer)
for scanner.Scan() {
mountLine := scanner.Text()
mountInfo := strings.Split(mountLine, " ")
mountType := mountInfo[0]
if mountType == "overlay" && strings.Contains(mountLine, mountPath) {
mountPoint := mountInfo[2]
Expect(syscall.Unmount(mountPoint, 0)).To(Succeed())
}
}
}
func CleanUpImages(storePath string) {
files, err := ioutil.ReadDir(filepath.Join(storePath, store.ImageDirName))
if err != nil {
return
}
for _, fileInfo := range files {
if fileInfo.IsDir() {
Expect(os.RemoveAll(filepath.Join(storePath, store.ImageDirName, fileInfo.Name()))).To(Succeed())
}
}
}