1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Separate non-Windows mount code from common code

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
This commit is contained in:
Paul "TBBle" Hampson 2020-11-05 23:47:18 +11:00
parent 080d9df63e
commit a158b53d86
4 changed files with 110 additions and 93 deletions

View file

@ -4,52 +4,9 @@ package mount // import "github.com/docker/docker/pkg/mount"
// Use github.com/moby/sys/mount and github.com/moby/sys/mountinfo instead.
import (
sysmount "github.com/moby/sys/mount"
"github.com/moby/sys/mountinfo"
)
// Deprecated: use github.com/moby/sys/mount instead.
//nolint:golint
var (
Mount = sysmount.Mount
ForceMount = sysmount.Mount // a deprecated synonym
Unmount = sysmount.Unmount
RecursiveUnmount = sysmount.RecursiveUnmount
)
// Deprecated: use github.com/moby/sys/mount instead.
//nolint:golint
const (
RDONLY = sysmount.RDONLY
NOSUID = sysmount.NOSUID
NOEXEC = sysmount.NOEXEC
SYNCHRONOUS = sysmount.SYNCHRONOUS
NOATIME = sysmount.NOATIME
BIND = sysmount.BIND
DIRSYNC = sysmount.DIRSYNC
MANDLOCK = sysmount.MANDLOCK
NODEV = sysmount.NODEV
NODIRATIME = sysmount.NODIRATIME
UNBINDABLE = sysmount.UNBINDABLE
RUNBINDABLE = sysmount.RUNBINDABLE
PRIVATE = sysmount.PRIVATE
RPRIVATE = sysmount.RPRIVATE
SHARED = sysmount.SHARED
RSHARED = sysmount.RSHARED
SLAVE = sysmount.SLAVE
RSLAVE = sysmount.RSLAVE
RBIND = sysmount.RBIND
RELATIME = sysmount.RELATIME
REMOUNT = sysmount.REMOUNT
STRICTATIME = sysmount.STRICTATIME
)
// Deprecated: use github.com/moby/sys/mount instead.
//nolint:golint
var (
MergeTmpfsOptions = sysmount.MergeTmpfsOptions
)
//nolint:golint
type (
// FilterFunc is a type.

View file

@ -0,0 +1,52 @@
// +build !darwin,!windows
package mount // import "github.com/docker/docker/pkg/mount"
// Deprecated: this package is not maintained and will be removed.
// Use github.com/moby/sys/mount and github.com/moby/sys/mountinfo instead.
import (
sysmount "github.com/moby/sys/mount"
)
// Deprecated: use github.com/moby/sys/mount instead.
//nolint:golint
var (
Mount = sysmount.Mount
ForceMount = sysmount.Mount // a deprecated synonym
Unmount = sysmount.Unmount
RecursiveUnmount = sysmount.RecursiveUnmount
)
// Deprecated: use github.com/moby/sys/mount instead.
//nolint:golint
const (
RDONLY = sysmount.RDONLY
NOSUID = sysmount.NOSUID
NOEXEC = sysmount.NOEXEC
SYNCHRONOUS = sysmount.SYNCHRONOUS
NOATIME = sysmount.NOATIME
BIND = sysmount.BIND
DIRSYNC = sysmount.DIRSYNC
MANDLOCK = sysmount.MANDLOCK
NODEV = sysmount.NODEV
NODIRATIME = sysmount.NODIRATIME
UNBINDABLE = sysmount.UNBINDABLE
RUNBINDABLE = sysmount.RUNBINDABLE
PRIVATE = sysmount.PRIVATE
RPRIVATE = sysmount.RPRIVATE
SHARED = sysmount.SHARED
RSHARED = sysmount.RSHARED
SLAVE = sysmount.SLAVE
RSLAVE = sysmount.RSLAVE
RBIND = sysmount.RBIND
RELATIME = sysmount.RELATIME
REMOUNT = sysmount.REMOUNT
STRICTATIME = sysmount.STRICTATIME
)
// Deprecated: use github.com/moby/sys/mount instead.
//nolint:golint
var (
MergeTmpfsOptions = sysmount.MergeTmpfsOptions
)

View file

@ -2,14 +2,7 @@ package system // import "github.com/docker/docker/pkg/system"
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
"time"
"github.com/moby/sys/mount"
"gotest.tools/v3/skip"
)
func TestEnsureRemoveAllNotExist(t *testing.T) {
@ -39,46 +32,3 @@ func TestEnsureRemoveAllWithFile(t *testing.T) {
t.Fatal(err)
}
}
func TestEnsureRemoveAllWithMount(t *testing.T) {
skip.If(t, runtime.GOOS == "windows", "mount not supported on Windows")
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
dir1, err := ioutil.TempDir("", "test-ensure-removeall-with-dir1")
if err != nil {
t.Fatal(err)
}
dir2, err := ioutil.TempDir("", "test-ensure-removeall-with-dir2")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir2)
bindDir := filepath.Join(dir1, "bind")
if err := os.MkdirAll(bindDir, 0755); err != nil {
t.Fatal(err)
}
if err := mount.Mount(dir2, bindDir, "none", "bind"); err != nil {
t.Fatal(err)
}
done := make(chan struct{}, 1)
go func() {
err = EnsureRemoveAll(dir1)
close(done)
}()
select {
case <-done:
if err != nil {
t.Fatal(err)
}
case <-time.After(5 * time.Second):
t.Fatal("timeout waiting for EnsureRemoveAll to finish")
}
if _, err := os.Stat(dir1); !os.IsNotExist(err) {
t.Fatalf("expected %q to not exist", dir1)
}
}

View file

@ -0,0 +1,58 @@
// +build !windows
package system // import "github.com/docker/docker/pkg/system"
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
"time"
"github.com/moby/sys/mount"
"gotest.tools/v3/skip"
)
func TestEnsureRemoveAllWithMount(t *testing.T) {
skip.If(t, runtime.GOOS == "windows", "mount not supported on Windows")
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
dir1, err := ioutil.TempDir("", "test-ensure-removeall-with-dir1")
if err != nil {
t.Fatal(err)
}
dir2, err := ioutil.TempDir("", "test-ensure-removeall-with-dir2")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir2)
bindDir := filepath.Join(dir1, "bind")
if err := os.MkdirAll(bindDir, 0755); err != nil {
t.Fatal(err)
}
if err := mount.Mount(dir2, bindDir, "none", "bind"); err != nil {
t.Fatal(err)
}
done := make(chan struct{}, 1)
go func() {
err = EnsureRemoveAll(dir1)
close(done)
}()
select {
case <-done:
if err != nil {
t.Fatal(err)
}
case <-time.After(5 * time.Second):
t.Fatal("timeout waiting for EnsureRemoveAll to finish")
}
if _, err := os.Stat(dir1); !os.IsNotExist(err) {
t.Fatalf("expected %q to not exist", dir1)
}
}