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.
This commit is contained in:
Klaus Post 2019-11-22 09:50:17 -08:00 committed by Harshavardhana
parent fb708b6b64
commit 890b493a2e

View File

@ -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
}