mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
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:
parent
fb708b6b64
commit
890b493a2e
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user