diff --git a/3rdparty/go b/3rdparty/go index 9d73c027d..f424c5a14 160000 --- a/3rdparty/go +++ b/3rdparty/go @@ -1 +1 @@ -Subproject commit 9d73c027da7775bbe94dbfd2552be487cbcbb260 +Subproject commit f424c5a14ab7601ddc4b4197a7ead12844ac930a diff --git a/src/tests/go/CMakeLists.txt b/src/tests/go/CMakeLists.txt index ac0a1675e..8108d18f3 100644 --- a/src/tests/go/CMakeLists.txt +++ b/src/tests/go/CMakeLists.txt @@ -6,10 +6,10 @@ add_custom_command( add_custom_command( OUTPUT gotest.a - DEPENDS gotest.go + DEPENDS gotest.go removeall.go COMMAND sh -c - "GOROOT='${CMAKE_SOURCE_DIR}/../3rdparty/go' '${CMAKE_SOURCE_DIR}/../3rdparty/go/bin/go' build -buildmode=c-archive ${CMAKE_CURRENT_SOURCE_DIR}/gotest.go" + "GOROOT='${CMAKE_SOURCE_DIR}/../3rdparty/go' '${CMAKE_SOURCE_DIR}/../3rdparty/go/bin/go' build -buildmode=c-archive ${CMAKE_CURRENT_SOURCE_DIR}/gotest.go ${CMAKE_CURRENT_SOURCE_DIR}/removeall.go" ) add_custom_target(gotestlib DEPENDS gotest.a) diff --git a/src/tests/go/gotest.go b/src/tests/go/gotest.go index 04d2c648d..4d4959794 100644 --- a/src/tests/go/gotest.go +++ b/src/tests/go/gotest.go @@ -55,6 +55,11 @@ func gotest(simulate bool) int32 { return -10 } + if err := testRemoveAll(); err != nil { + fmt.Println(err) + return -11 + } + return 42 // success magic } diff --git a/src/tests/go/removeall.go b/src/tests/go/removeall.go new file mode 100644 index 000000000..db5b61a97 --- /dev/null +++ b/src/tests/go/removeall.go @@ -0,0 +1,80 @@ +// Copyright 2024 Edgeless Systems GmbH. All rights reserved. +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "os" + "path/filepath" +) + +func testRemoveAll() error { + tmpDir := "/removeall-test" + if err := os.Mkdir(tmpDir, 0o400); err != nil { + return err + } + + if err := os.RemoveAll(""); err != nil { + return fmt.Errorf("RemoveAll(\"\"): %v; want nil", err) + } + + file := filepath.Join(tmpDir, "file") + path := filepath.Join(tmpDir, "_TestRemoveAll_") + fpath := filepath.Join(path, "file") + dpath := filepath.Join(path, "dir") + + // Make a regular file and remove + fd, err := os.Create(file) + if err != nil { + return fmt.Errorf("create %q: %s", file, err) + } + fd.Close() + if err = os.RemoveAll(file); err != nil { + return fmt.Errorf("RemoveAll %q (first): %s", file, err) + } + if _, err = os.Lstat(file); err == nil { + return fmt.Errorf("Lstat %q succeeded after RemoveAll (first)", file) + } + + // Make directory with 1 file and remove. + if err := os.MkdirAll(path, 0777); err != nil { + return fmt.Errorf("MkdirAll %q: %s", path, err) + } + fd, err = os.Create(fpath) + if err != nil { + return fmt.Errorf("create %q: %s", fpath, err) + } + fd.Close() + if err = os.RemoveAll(path); err != nil { + return fmt.Errorf("RemoveAll %q (second): %s", path, err) + } + if _, err = os.Lstat(path); err == nil { + return fmt.Errorf("Lstat %q succeeded after RemoveAll (second)", path) + } + + // Make directory with file and subdirectory and remove. + if err = os.MkdirAll(dpath, 0777); err != nil { + return fmt.Errorf("MkdirAll %q: %s", dpath, err) + } + fd, err = os.Create(fpath) + if err != nil { + return fmt.Errorf("create %q: %s", fpath, err) + } + fd.Close() + fd, err = os.Create(dpath + "/file") + if err != nil { + return fmt.Errorf("create %q: %s", fpath, err) + } + fd.Close() + if err = os.RemoveAll(path); err != nil { + return fmt.Errorf("RemoveAll %q (third): %s", path, err) + } + if _, err := os.Lstat(path); err == nil { + return fmt.Errorf("Lstat %q succeeded after RemoveAll (third)", path) + } + + return nil +}