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.
master
Klaus Post 5 years ago committed by Harshavardhana
parent fb708b6b64
commit 890b493a2e
  1. 9
      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
}

Loading…
Cancel
Save