From 84bd2490f00360ba83f47bc27d80e2cda36b773a Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Tue, 3 Sep 2019 00:35:41 +0100 Subject: [PATCH] Make sure we use a random fs-name We were getting fs-name clashes due to the deterministic random number generator. As such, we had fs-ansible failures due to the same fs_name being used in two places. --- internal/pkg/filesystem_impl/provider.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/pkg/filesystem_impl/provider.go b/internal/pkg/filesystem_impl/provider.go index 6624a92d..9b95c851 100644 --- a/internal/pkg/filesystem_impl/provider.go +++ b/internal/pkg/filesystem_impl/provider.go @@ -4,6 +4,7 @@ import ( "github.com/RSE-Cambridge/data-acc/internal/pkg/datamodel" "github.com/RSE-Cambridge/data-acc/internal/pkg/filesystem" "math/rand" + "time" ) func NewFileSystemProvider(ansible filesystem.Ansible) filesystem.Provider { @@ -17,10 +18,13 @@ type fileSystemProvider struct { const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +var source = rand.NewSource(time.Now().UnixNano()) +var randGenerator = rand.New(source) + func GetNewUUID() string { b := make([]byte, 8) for i := range b { - b[i] = letters[rand.Int63()%int64(len(letters))] + b[i] = letters[randGenerator.Int63()%int64(len(letters))] } return string(b) }