Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-08-25 13:55:39 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-08-25 13:57:25 +0300
commitbe5da4f7a8bf517d9d8592e405724c2c9a0754e3 (patch)
treef9ad145dacd171162e34865fa65163f565673ae6
parent7d83e7560ef6412dfb0a9421c38969f5f69cb90d (diff)
testhelper: Do not copy binaries in case they already exist
When building binaries, we always copy the resulting binaries into the target location. This is not required though in case we have already built and copied the binary before, and in fact it even causes issues if the binary exists already and is still in use. Fix this by not copying the binary in case it already exists.
-rw-r--r--internal/testhelper/build.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/internal/testhelper/build.go b/internal/testhelper/build.go
index 0b5889a7c..196a0d5ba 100644
--- a/internal/testhelper/build.go
+++ b/internal/testhelper/build.go
@@ -58,13 +58,21 @@ func buildBinary(t testing.TB, dstDir, name string, buildOnce *sync.Once) {
binPath := filepath.Join(binsPath, name)
defer func() {
- if !t.Failed() {
- // copy compiled binary to the destination folder
- require.NoError(t, os.MkdirAll(dstDir, os.ModePerm))
- targetPath := filepath.Join(dstDir, name)
- CopyFile(t, binPath, targetPath)
- require.NoError(t, os.Chmod(targetPath, 0777))
+ if t.Failed() {
+ return
+ }
+
+ targetPath := filepath.Join(dstDir, name)
+
+ // Exit early if the file exists.
+ if _, err := os.Stat(targetPath); err == nil {
+ return
}
+
+ // copy compiled binary to the destination folder
+ require.NoError(t, os.MkdirAll(dstDir, os.ModePerm))
+ CopyFile(t, binPath, targetPath)
+ require.NoError(t, os.Chmod(targetPath, 0777))
}()
buildOnce.Do(func() {