mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-11-04 14:49:53 +08:00
23 lines
509 B
Go
23 lines
509 B
Go
package cgroup
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
// EnsureDirExists creates directories if the path not exists
|
|
func EnsureDirExists(path string) error {
|
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
|
return os.MkdirAll(path, dirPerm)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// CreateSubCgroupPath creates path for sub-cgroup with given group and prefix
|
|
func CreateSubCgroupPath(group, prefix string) (string, error) {
|
|
base := path.Join(basePath, group, prefix)
|
|
EnsureDirExists(base)
|
|
return ioutil.TempDir(base, "")
|
|
}
|