From 890b493a2e32d7f607e5ee0150a9ce884c3e26ff Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 22 Nov 2019 09:50:17 -0800 Subject: [PATCH] Use random file name for write check (#8563) Since there may be multiple writes going on concurrently Use a random file name for the write check to avoid collisions. --- cmd/posix.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/posix.go b/cmd/posix.go index d19d07dd2..bafebde07 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -19,6 +19,8 @@ package cmd import ( "bufio" "context" + "crypto/rand" + "encoding/hex" "errors" "io" "io/ioutil" @@ -154,12 +156,15 @@ func getValidPath(path string) (string, error) { } // check if backend is writable. - file, err := os.Create(pathJoin(path, ".writable-check.tmp")) + var rnd [8]byte + _, _ = rand.Read(rnd[:]) + fn := pathJoin(path, ".writable-check-"+hex.EncodeToString(rnd[:])+".tmp") + file, err := os.Create(fn) if err != nil { return path, err } - defer os.Remove(pathJoin(path, ".writable-check.tmp")) file.Close() + os.Remove(fn) return path, nil }