Fix runtime path created by multiple processes (#11966)

Signed-off-by: dragondriver <jiquan.long@zilliz.com>
This commit is contained in:
dragondriver 2021-11-17 17:47:12 +08:00 committed by GitHub
parent ba9977951a
commit cc0d6dc6fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,17 +142,14 @@ func stopPid(filename string, runtimeDir string) error {
} }
func makeRuntimeDir(dir string) error { func makeRuntimeDir(dir string) error {
st, err := os.Stat(dir) perm := os.FileMode(0755)
if os.IsNotExist(err) { // os.MkdirAll equal to `mkdir -p`
err = os.Mkdir(dir, 0755) err := os.MkdirAll(dir, perm)
if err != nil { if err != nil {
return fmt.Errorf("create runtime dir %s failed", dir) // err will be raised only when dir exists and dir is a file instead of a directory.
} return fmt.Errorf("create runtime dir %s failed, err: %s", dir, err.Error())
return nil
}
if !st.IsDir() {
return fmt.Errorf("%s is not directory", dir)
} }
tmpFile, err := ioutil.TempFile(dir, "tmp") tmpFile, err := ioutil.TempFile(dir, "tmp")
if err != nil { if err != nil {
return err return err