Fix runtime path created by multiple processes (#11966)

Signed-off-by: dragondriver <jiquan.long@zilliz.com>
pull/12006/head
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
1 changed files with 7 additions and 10 deletions

View File

@ -142,17 +142,14 @@ func stopPid(filename string, runtimeDir string) error {
}
func makeRuntimeDir(dir string) error {
st, err := os.Stat(dir)
if os.IsNotExist(err) {
err = os.Mkdir(dir, 0755)
if err != nil {
return fmt.Errorf("create runtime dir %s failed", dir)
}
return nil
}
if !st.IsDir() {
return fmt.Errorf("%s is not directory", dir)
perm := os.FileMode(0755)
// os.MkdirAll equal to `mkdir -p`
err := os.MkdirAll(dir, perm)
if err != nil {
// 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())
}
tmpFile, err := ioutil.TempFile(dir, "tmp")
if err != nil {
return err