From 83b946c4330263bc143c6f6586179ab914422f6b Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 27 Oct 2021 13:27:39 -0700 Subject: [PATCH 1/4] Drop go < 1.16 compatibility Go 1.15 is not supported since Go 1.17 release in August 2021. This is mostly so we can use replacements for ioutil functions (note that we do not have to replace all ioutil uses for now, as it is still not deprecated), as well as testing.TestDir and such. Signed-off-by: Kir Kolyshkin --- .github/workflows/test.yml | 2 +- mount/go.mod | 2 +- mountinfo/go.mod | 2 +- signal/go.mod | 2 +- symlink/go.mod | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0a3cb4cf..d7e2c4ea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.15.x, 1.16.x, 1.17.x] + go-version: [1.16.x, 1.17.x] platform: [ubuntu-20.04, windows-latest, macos-11] runs-on: ${{ matrix.platform }} steps: diff --git a/mount/go.mod b/mount/go.mod index b08f0109..5dfd9e6a 100644 --- a/mount/go.mod +++ b/mount/go.mod @@ -1,6 +1,6 @@ module github.com/moby/sys/mount -go 1.14 +go 1.16 require ( github.com/moby/sys/mountinfo v0.4.1 diff --git a/mountinfo/go.mod b/mountinfo/go.mod index 9749ea96..696666a4 100644 --- a/mountinfo/go.mod +++ b/mountinfo/go.mod @@ -1,5 +1,5 @@ module github.com/moby/sys/mountinfo -go 1.14 +go 1.16 require golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 diff --git a/signal/go.mod b/signal/go.mod index c48d5aec..e758d471 100644 --- a/signal/go.mod +++ b/signal/go.mod @@ -1,5 +1,5 @@ module github.com/moby/sys/signal -go 1.13 +go 1.16 require golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c diff --git a/symlink/go.mod b/symlink/go.mod index a6516900..307d2e1a 100644 --- a/symlink/go.mod +++ b/symlink/go.mod @@ -1,5 +1,5 @@ module github.com/moby/sys/symlink -go 1.14 +go 1.16 require golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 From 39936d90c39a2663c21e40366cd507cee62eb039 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 27 Oct 2021 13:31:33 -0700 Subject: [PATCH 2/4] symlink: use t.TempDir in tests Signed-off-by: Kir Kolyshkin --- symlink/fs_unix_test.go | 50 ++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/symlink/fs_unix_test.go b/symlink/fs_unix_test.go index 258c78ae..d2e54c7b 100644 --- a/symlink/fs_unix_test.go +++ b/symlink/fs_unix_test.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows // Licensed under the Apache License, Version 2.0; See LICENSE.APACHE @@ -6,7 +7,6 @@ package symlink import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -53,7 +53,7 @@ func testSymlink(tmpdir, path, expected, scope string) error { } func TestFollowSymlinkAbsolute(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/d", target: "/b"}}); err != nil { t.Fatal(err) @@ -64,7 +64,7 @@ func TestFollowSymlinkAbsolute(t *testing.T) { } func TestFollowSymlinkRelativePath(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/i", target: "a"}}); err != nil { t.Fatal(err) @@ -75,7 +75,7 @@ func TestFollowSymlinkRelativePath(t *testing.T) { } func TestFollowSymlinkSkipSymlinksOutsideScope(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{ {path: "linkdir", target: "realdir"}, @@ -95,7 +95,7 @@ func TestFollowSymlinkInvalidScopePathPair(t *testing.T) { } func TestFollowSymlinkLastLink(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/d", target: "/b"}}); err != nil { t.Fatal(err) @@ -106,7 +106,7 @@ func TestFollowSymlinkLastLink(t *testing.T) { } func TestFollowSymlinkRelativeLinkChangeScope(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/e", target: "../b"}}); err != nil { t.Fatal(err) @@ -122,7 +122,7 @@ func TestFollowSymlinkRelativeLinkChangeScope(t *testing.T) { } func TestFollowSymlinkDeepRelativeLinkChangeScope(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/f", target: "../../../../test"}}); err != nil { t.Fatal(err) @@ -142,7 +142,7 @@ func TestFollowSymlinkDeepRelativeLinkChangeScope(t *testing.T) { } func TestFollowSymlinkRelativeLinkChain(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() // avoid letting symlink g (pointed at by symlink h) take out of scope // TODO: we should probably normalize to scope here because ../[....]/root @@ -159,7 +159,7 @@ func TestFollowSymlinkRelativeLinkChain(t *testing.T) { } func TestFollowSymlinkBreakoutPath(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() // avoid letting symlink -> ../directory/file escape from scope // normalize to "testdata/fs/j" @@ -172,7 +172,7 @@ func TestFollowSymlinkBreakoutPath(t *testing.T) { } func TestFollowSymlinkToRoot(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() // make sure we don't allow escaping to / // normalize to dir @@ -185,7 +185,7 @@ func TestFollowSymlinkToRoot(t *testing.T) { } func TestFollowSymlinkSlashDotdot(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() tmpdir = filepath.Join(tmpdir, "dir", "subdir") // make sure we don't allow escaping to / @@ -199,7 +199,7 @@ func TestFollowSymlinkSlashDotdot(t *testing.T) { } func TestFollowSymlinkDotdot(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() tmpdir = filepath.Join(tmpdir, "dir", "subdir") // make sure we stay in scope without leaking information @@ -214,7 +214,7 @@ func TestFollowSymlinkDotdot(t *testing.T) { } func TestFollowSymlinkRelativePath2(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{{path: "bar/foo", target: "baz/target"}}); err != nil { t.Fatal(err) @@ -225,7 +225,7 @@ func TestFollowSymlinkRelativePath2(t *testing.T) { } func TestFollowSymlinkScopeLink(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{ {path: "root2"}, @@ -240,7 +240,7 @@ func TestFollowSymlinkScopeLink(t *testing.T) { } func TestFollowSymlinkRootScope(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() expected, err := filepath.EvalSymlinks(tmpdir) if err != nil { @@ -270,7 +270,7 @@ func TestFollowSymlinkEmpty(t *testing.T) { } func TestFollowSymlinkCircular(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{{path: "root/foo", target: "foo"}}); err != nil { t.Fatal(err) @@ -292,7 +292,7 @@ func TestFollowSymlinkCircular(t *testing.T) { } func TestFollowSymlinkComplexChainWithTargetPathsContainingLinks(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{ {path: "root2"}, @@ -312,7 +312,7 @@ func TestFollowSymlinkComplexChainWithTargetPathsContainingLinks(t *testing.T) { } func TestFollowSymlinkBreakoutNonExistent(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{ {path: "root/slash", target: "/"}, @@ -326,7 +326,7 @@ func TestFollowSymlinkBreakoutNonExistent(t *testing.T) { } func TestFollowSymlinkNoLexicalCleaning(t *testing.T) { - tmpdir := mkTempDir(t) + tmpdir := t.TempDir() if err := makeFs(tmpdir, []dirOrLink{ {path: "root/sym", target: "/foo/bar"}, @@ -338,15 +338,3 @@ func TestFollowSymlinkNoLexicalCleaning(t *testing.T) { t.Fatal(err) } } - -// TODO use testing.TempDir() instead (https://golang.org/pkg/testing/#T.TempDir) -// once we no longer test on Go 1.14 and older. -func mkTempDir(t *testing.T) string { - t.Helper() - tmpdir, err := ioutil.TempDir("", t.Name()) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = os.RemoveAll(tmpdir) }) - return tmpdir -} From 7ecd1bfd85e5a82d5038af7ae32ad88e3630ad54 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 27 Oct 2021 13:38:08 -0700 Subject: [PATCH 3/4] all: add go 1.17+ go:build tags Signed-off-by: Kir Kolyshkin --- mount/flags_bsd.go | 1 + mount/flags_unix.go | 1 + mount/mount_errors.go | 1 + mount/mount_unix.go | 1 + mount/mount_unix_test.go | 1 + mount/mounter_freebsd.go | 1 + mount/mounter_openbsd.go | 1 + mount/mounter_unsupported.go | 1 + mountinfo/mounted_unix.go | 1 + mountinfo/mountinfo_bsd.go | 1 + mountinfo/mountinfo_test.go | 1 + mountinfo/mountinfo_unsupported.go | 1 + signal/signal_linux.go | 1 + signal/signal_linux_mipsx.go | 1 + signal/signal_linux_test.go | 1 + signal/signal_unix.go | 1 + signal/signal_unsupported.go | 1 + symlink/fs_unix.go | 1 + 18 files changed, 18 insertions(+) diff --git a/mount/flags_bsd.go b/mount/flags_bsd.go index 27d8440a..a7f8a719 100644 --- a/mount/flags_bsd.go +++ b/mount/flags_bsd.go @@ -1,3 +1,4 @@ +//go:build freebsd || openbsd // +build freebsd openbsd package mount diff --git a/mount/flags_unix.go b/mount/flags_unix.go index 98cbb75c..19fa61fc 100644 --- a/mount/flags_unix.go +++ b/mount/flags_unix.go @@ -1,3 +1,4 @@ +//go:build !darwin && !windows // +build !darwin,!windows package mount diff --git a/mount/mount_errors.go b/mount/mount_errors.go index 936a2637..2bd1ef7f 100644 --- a/mount/mount_errors.go +++ b/mount/mount_errors.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package mount diff --git a/mount/mount_unix.go b/mount/mount_unix.go index a250bfc8..1dc0deef 100644 --- a/mount/mount_unix.go +++ b/mount/mount_unix.go @@ -1,3 +1,4 @@ +//go:build !darwin && !windows // +build !darwin,!windows package mount diff --git a/mount/mount_unix_test.go b/mount/mount_unix_test.go index 2c10d74b..019c0af9 100644 --- a/mount/mount_unix_test.go +++ b/mount/mount_unix_test.go @@ -1,3 +1,4 @@ +//go:build !darwin && !windows // +build !darwin,!windows package mount diff --git a/mount/mounter_freebsd.go b/mount/mounter_freebsd.go index 9b2d26c4..1fffb690 100644 --- a/mount/mounter_freebsd.go +++ b/mount/mounter_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd && cgo // +build freebsd,cgo package mount diff --git a/mount/mounter_openbsd.go b/mount/mounter_openbsd.go index 28cddf16..3c0718b9 100644 --- a/mount/mounter_openbsd.go +++ b/mount/mounter_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd && cgo // +build openbsd,cgo /* diff --git a/mount/mounter_unsupported.go b/mount/mounter_unsupported.go index e7ff5bd9..31fb7235 100644 --- a/mount/mounter_unsupported.go +++ b/mount/mounter_unsupported.go @@ -1,3 +1,4 @@ +//go:build (!linux && !freebsd && !openbsd && !windows) || (freebsd && !cgo) || (openbsd && !cgo) // +build !linux,!freebsd,!openbsd,!windows freebsd,!cgo openbsd,!cgo package mount diff --git a/mountinfo/mounted_unix.go b/mountinfo/mounted_unix.go index 7ad969a2..da3828eb 100644 --- a/mountinfo/mounted_unix.go +++ b/mountinfo/mounted_unix.go @@ -1,3 +1,4 @@ +//go:build linux || (freebsd && cgo) || (openbsd && cgo) || (darwin && cgo) // +build linux freebsd,cgo openbsd,cgo darwin,cgo package mountinfo diff --git a/mountinfo/mountinfo_bsd.go b/mountinfo/mountinfo_bsd.go index 0e8ab6a0..337f500f 100644 --- a/mountinfo/mountinfo_bsd.go +++ b/mountinfo/mountinfo_bsd.go @@ -1,3 +1,4 @@ +//go:build (freebsd && cgo) || (openbsd && cgo) || (darwin && cgo) // +build freebsd,cgo openbsd,cgo darwin,cgo package mountinfo diff --git a/mountinfo/mountinfo_test.go b/mountinfo/mountinfo_test.go index aec4356f..3e124593 100644 --- a/mountinfo/mountinfo_test.go +++ b/mountinfo/mountinfo_test.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package mountinfo diff --git a/mountinfo/mountinfo_unsupported.go b/mountinfo/mountinfo_unsupported.go index c3ef2262..95769a76 100644 --- a/mountinfo/mountinfo_unsupported.go +++ b/mountinfo/mountinfo_unsupported.go @@ -1,3 +1,4 @@ +//go:build (!windows && !linux && !freebsd && !openbsd && !darwin) || (freebsd && !cgo) || (openbsd && !cgo) || (darwin && !cgo) // +build !windows,!linux,!freebsd,!openbsd,!darwin freebsd,!cgo openbsd,!cgo darwin,!cgo package mountinfo diff --git a/signal/signal_linux.go b/signal/signal_linux.go index 692b9f9e..f2f65889 100644 --- a/signal/signal_linux.go +++ b/signal/signal_linux.go @@ -1,3 +1,4 @@ +//go:build !mips && !mipsle && !mips64 && !mips64le // +build !mips,!mipsle,!mips64,!mips64le package signal diff --git a/signal/signal_linux_mipsx.go b/signal/signal_linux_mipsx.go index 138a840c..72f035ae 100644 --- a/signal/signal_linux_mipsx.go +++ b/signal/signal_linux_mipsx.go @@ -1,3 +1,4 @@ +//go:build linux && (mips || mipsle || mips64 || mips64le) // +build linux // +build mips mipsle mips64 mips64le diff --git a/signal/signal_linux_test.go b/signal/signal_linux_test.go index b1bdd3a8..59f0283d 100644 --- a/signal/signal_linux_test.go +++ b/signal/signal_linux_test.go @@ -1,3 +1,4 @@ +//go:build darwin || linux // +build darwin linux package signal diff --git a/signal/signal_unix.go b/signal/signal_unix.go index 10f20093..93f01e28 100644 --- a/signal/signal_unix.go +++ b/signal/signal_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package signal diff --git a/signal/signal_unsupported.go b/signal/signal_unsupported.go index 161ba273..f4200fbc 100644 --- a/signal/signal_unsupported.go +++ b/signal/signal_unsupported.go @@ -1,3 +1,4 @@ +//go:build !linux && !darwin && !freebsd && !windows // +build !linux,!darwin,!freebsd,!windows package signal diff --git a/symlink/fs_unix.go b/symlink/fs_unix.go index ef960a08..13ce8251 100644 --- a/symlink/fs_unix.go +++ b/symlink/fs_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package symlink From fb8a7cb559eaa927551ce54636883a9be8c5ca62 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 27 Oct 2021 13:45:18 -0700 Subject: [PATCH 4/4] all: bump golang.org/x/sys/unix This is mostly to have the same x/sys/unix version in all modules. Signed-off-by: Kir Kolyshkin --- mount/go.mod | 2 +- mount/go.sum | 4 ++-- mountinfo/go.mod | 2 +- mountinfo/go.sum | 4 ++-- signal/go.mod | 2 +- signal/go.sum | 4 ++-- symlink/go.mod | 2 +- symlink/go.sum | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mount/go.mod b/mount/go.mod index 5dfd9e6a..8b6693c2 100644 --- a/mount/go.mod +++ b/mount/go.mod @@ -4,5 +4,5 @@ go 1.16 require ( github.com/moby/sys/mountinfo v0.4.1 - golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 + golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 ) diff --git a/mount/go.sum b/mount/go.sum index a2a62b95..e3830f48 100644 --- a/mount/go.sum +++ b/mount/go.sum @@ -1,5 +1,5 @@ github.com/moby/sys/mountinfo v0.4.1 h1:1O+1cHA1aujwEwwVMa2Xm2l+gIpUHyd3+D+d7LZh1kM= github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 h1:YEu4SMq7D0cmT7CBbXfcH0NZeuChAXwsHe/9XueUO6o= -golang.org/x/sys v0.0.0-20200922070232-aee5d888a860/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/mountinfo/go.mod b/mountinfo/go.mod index 696666a4..1cc3efcf 100644 --- a/mountinfo/go.mod +++ b/mountinfo/go.mod @@ -2,4 +2,4 @@ module github.com/moby/sys/mountinfo go 1.16 -require golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 +require golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 diff --git a/mountinfo/go.sum b/mountinfo/go.sum index 2a5be7ea..c257a6a2 100644 --- a/mountinfo/go.sum +++ b/mountinfo/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM= -golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/signal/go.mod b/signal/go.mod index e758d471..a9e44368 100644 --- a/signal/go.mod +++ b/signal/go.mod @@ -2,4 +2,4 @@ module github.com/moby/sys/signal go 1.16 -require golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c +require golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 diff --git a/signal/go.sum b/signal/go.sum index 0f478630..c257a6a2 100644 --- a/signal/go.sum +++ b/signal/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/symlink/go.mod b/symlink/go.mod index 307d2e1a..1c18b6a0 100644 --- a/symlink/go.mod +++ b/symlink/go.mod @@ -2,4 +2,4 @@ module github.com/moby/sys/symlink go 1.16 -require golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 +require golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 diff --git a/symlink/go.sum b/symlink/go.sum index 35f1a82a..c257a6a2 100644 --- a/symlink/go.sum +++ b/symlink/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 h1:YEu4SMq7D0cmT7CBbXfcH0NZeuChAXwsHe/9XueUO6o= -golang.org/x/sys v0.0.0-20200922070232-aee5d888a860/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=