Created
November 16, 2018 01:32
-
-
Save niski84/6de03e835819eb5273a0f5426e43257f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create DB Dirs creates dirs for postgress tabelspace(s) | |
// replaces tokens contained in the configMap | |
func CreateDBDirs(dirs []string, configMap map[string]string) (err error) { | |
for _, dir := range dirs { | |
dir = TokenReplace(dir, configMap) | |
_, err := os.Stat(dir) | |
if err != nil { | |
if os.IsNotExist(err) { | |
log.Println("creating tablespace dir:", dir) | |
// for windows, force \ in path | |
if runtime.GOOS == "windows" { | |
dir = strings.Replace(dir,`/`, `\`, -1 ) | |
} | |
err := os.MkdirAll(dir, os.FileMode(0775)) | |
if err != nil { | |
return fmt.Errorf("error creating tabelspace folders: %v ", err.Error()) | |
} | |
if runtime.GOOS != "windows" { | |
group, err := user.Lookup("postgres") | |
if err != nil { | |
return fmt.Errorf("error looking up postgres user user info") | |
} | |
uid,_ := strconv.Atoi(group.Uid) | |
gid,_ := strconv.Atoi(group.Gid) | |
log.Printf(`Setting uid to "%v" and gid to "%v" for dir %v`, uid, gid, dir) | |
err = os.Chown(dir, uid, gid) | |
if err != nil { | |
log.Println(err) | |
} | |
} | |
} else { | |
return err | |
} | |
} | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment