mirror of
https://github.com/lwch/natpass
synced 2025-09-30 03:22:05 +08:00
22 lines
396 B
Go
22 lines
396 B
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"os/user"
|
|
"strconv"
|
|
|
|
"github.com/lwch/runtime"
|
|
)
|
|
|
|
// BuildDir mkdir and chown
|
|
func BuildDir(dir, u string) {
|
|
runtime.Assert(os.MkdirAll(dir, 0755))
|
|
if len(u) > 0 {
|
|
us, err := user.Lookup(u)
|
|
runtime.Assert(err)
|
|
uid, _ := strconv.ParseInt(us.Uid, 10, 32)
|
|
gid, _ := strconv.ParseInt(us.Gid, 10, 32)
|
|
runtime.Assert(os.Chown(dir, int(uid), int(gid)))
|
|
}
|
|
}
|