@@ -19,12 +19,12 @@ import (
1919 "net"
2020 "strings"
2121
22+ "github.com/moby/sys/mountinfo"
23+ "github.com/sealerio/sealer/utils/ssh"
2224 "github.com/shirou/gopsutil/disk"
2325 "github.com/sirupsen/logrus"
2426
25- "github.com/sealerio/sealer/utils/exec"
2627 "github.com/sealerio/sealer/utils/os/fs"
27- "github.com/sealerio/sealer/utils/ssh"
2828 strUtils "github.com/sealerio/sealer/utils/strings"
2929)
3030
@@ -120,6 +120,18 @@ func NewMountService(target, upper string, lowLayers []string) (Service, error)
120120 }, nil
121121}
122122
123+ func GetDirNameListInDir (dir string ) ([]string , error ) {
124+ var dirs []string
125+ infos , err := mountinfo .GetMounts (mountinfo .PrefixFilter (dir ))
126+ if err != nil {
127+ return dirs , err
128+ }
129+ for _ , info := range infos {
130+ dirs = append (dirs , info .Mountpoint )
131+ }
132+ return dirs , nil
133+ }
134+
123135//NewMountServiceByTarget will filter file system by target,if not existed,return false.
124136func NewMountServiceByTarget (target string ) Service {
125137 mounted , info := GetMountDetails (target )
@@ -141,12 +153,11 @@ type Info struct {
141153}
142154
143155func GetMountDetails (target string ) (bool , * Info ) {
144- cmd := fmt .Sprintf ("mount | grep %s" , target )
145- result , err := exec .RunSimpleCmd (cmd )
156+ infos , err := mountinfo .GetMounts (mountinfo .SingleEntryFilter (target ))
146157 if err != nil {
147158 return false , nil
148159 }
149- return mountCmdResultSplit (result , target )
160+ return mountCmdResultSplit (infos [ 0 ]. VFSOptions , target )
150161}
151162
152163func GetRemoteMountDetails (s ssh.Interface , ip net.IP , target string ) (bool , * Info ) {
0 commit comments