From b950b778c22b2b2bd57002c0dcb81fb6e90c253d Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 29 Nov 2021 19:17:52 -0800 Subject: [PATCH] libct/utils: ResolveRootfs: remove Since commit 8850636eb3df747f (February 2015) this function is no longer used (replaced by (*ConfigValidator).rootfs), so let's remove it, together with its unit tests (which were added by commit 917c1f6d6 in April 2016). Signed-off-by: Kir Kolyshkin --- libcontainer/utils/utils.go | 10 ------- libcontainer/utils/utils_test.go | 47 -------------------------------- 2 files changed, 57 deletions(-) diff --git a/libcontainer/utils/utils.go b/libcontainer/utils/utils.go index a430a2b93..6b9fc3435 100644 --- a/libcontainer/utils/utils.go +++ b/libcontainer/utils/utils.go @@ -33,16 +33,6 @@ func init() { } } -// ResolveRootfs ensures that the current working directory is -// not a symlink and returns the absolute path to the rootfs -func ResolveRootfs(uncleanRootfs string) (string, error) { - rootfs, err := filepath.Abs(uncleanRootfs) - if err != nil { - return "", err - } - return filepath.EvalSymlinks(rootfs) -} - // ExitStatus returns the correct exit status for a process based on if it // was signaled or exited cleanly func ExitStatus(status unix.WaitStatus) int { diff --git a/libcontainer/utils/utils_test.go b/libcontainer/utils/utils_test.go index 4dc951c6f..52fc93639 100644 --- a/libcontainer/utils/utils_test.go +++ b/libcontainer/utils/utils_test.go @@ -2,8 +2,6 @@ package utils import ( "bytes" - "os" - "path/filepath" "testing" "golang.org/x/sys/unix" @@ -30,51 +28,6 @@ func TestSearchLabels(t *testing.T) { } } -func TestResolveRootfs(t *testing.T) { - dir := "rootfs" - if err := os.Mkdir(dir, 0o600); err != nil { - t.Fatal(err) - } - defer os.Remove(dir) - - path, err := ResolveRootfs(dir) - if err != nil { - t.Fatal(err) - } - pwd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - if path != pwd+"/rootfs" { - t.Errorf("expected rootfs to be abs and was %s", path) - } -} - -func TestResolveRootfsWithSymlink(t *testing.T) { - dir := "rootfs" - tmpDir, _ := filepath.EvalSymlinks(os.TempDir()) - if err := os.Symlink(tmpDir, dir); err != nil { - t.Fatal(err) - } - defer os.Remove(dir) - - path, err := ResolveRootfs(dir) - if err != nil { - t.Fatal(err) - } - - if path != tmpDir { - t.Errorf("expected rootfs to be the real path %s and was %s", path, os.TempDir()) - } -} - -func TestResolveRootfsWithNonExistingDir(t *testing.T) { - _, err := ResolveRootfs("foo") - if err == nil { - t.Error("expected error to happen but received nil") - } -} - func TestExitStatus(t *testing.T) { status := unix.WaitStatus(0) ex := ExitStatus(status)