Selaa lähdekoodia

pkg/mount: update deprecated wrappers

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 4 vuotta sitten
vanhempi
commit
e766361271
1 muutettua tiedostoa jossa 43 lisäystä ja 6 poistoa
  1. 43 6
      pkg/mount/deprecated.go

+ 43 - 6
pkg/mount/deprecated.go

@@ -54,20 +54,57 @@ var (
 type (
 type (
 	// FilterFunc is a type.
 	// FilterFunc is a type.
 	// Deprecated: use github.com/moby/sys/mountinfo instead.
 	// Deprecated: use github.com/moby/sys/mountinfo instead.
-	FilterFunc = mountinfo.FilterFunc
-	// Info is a type.
+	FilterFunc = func(*Info) (skip, stop bool)
+
+	// Info is a type
 	// Deprecated: use github.com/moby/sys/mountinfo instead.
 	// Deprecated: use github.com/moby/sys/mountinfo instead.
-	Info = mountinfo.Info // Info is deprecated
+	Info struct {
+		ID, Parent, Major, Minor                                  int
+		Root, Mountpoint, Opts, Optional, Fstype, Source, VfsOpts string
+	}
 )
 )
 
 
 // Deprecated: use github.com/moby/sys/mountinfo instead.
 // Deprecated: use github.com/moby/sys/mountinfo instead.
 //nolint:golint
 //nolint:golint
 var (
 var (
-	Mounted   = mountinfo.Mounted
-	GetMounts = mountinfo.GetMounts
-
+	Mounted           = mountinfo.Mounted
 	PrefixFilter      = mountinfo.PrefixFilter
 	PrefixFilter      = mountinfo.PrefixFilter
 	SingleEntryFilter = mountinfo.SingleEntryFilter
 	SingleEntryFilter = mountinfo.SingleEntryFilter
 	ParentsFilter     = mountinfo.ParentsFilter
 	ParentsFilter     = mountinfo.ParentsFilter
 	FstypeFilter      = mountinfo.FSTypeFilter
 	FstypeFilter      = mountinfo.FSTypeFilter
 )
 )
+
+// GetMounts is a function.
+//
+// Deprecated: use github.com/moby/sys/mountinfo.GetMounts() instead.
+//nolint:golint
+func GetMounts(f FilterFunc) ([]*Info, error) {
+	fi := func(i *mountinfo.Info) (skip, stop bool) {
+		return f(toLegacyInfo(i))
+	}
+
+	mounts, err := mountinfo.GetMounts(fi)
+	if err != nil {
+		return nil, err
+	}
+	mi := make([]*Info, len(mounts))
+	for i, m := range mounts {
+		mi[i] = toLegacyInfo(m)
+	}
+	return mi, nil
+}
+
+func toLegacyInfo(m *mountinfo.Info) *Info {
+	return &Info{
+		ID:         m.ID,
+		Parent:     m.Parent,
+		Major:      m.Major,
+		Minor:      m.Minor,
+		Root:       m.Root,
+		Mountpoint: m.Mountpoint,
+		Opts:       m.Options,
+		Fstype:     m.FSType,
+		Source:     m.Source,
+		VfsOpts:    m.VFSOptions,
+	}
+}