-
-// Helper functions
-
-func createFile(path string, data string, mode fs.FileMode) {
- err := os.WriteFile(path, []byte(data), 0644)
- if err != nil {
- panic(err)
- }
- err = os.Chmod(path, mode)
- if err != nil {
- panic(err)
- }
-}
-func createSymlink(path string, data string) {
- err := os.Symlink(data, path)
- if err != nil {
- panic(err)
- }
-}
-func createDirectory(path string, mode fs.FileMode) {
- err := os.Mkdir(path, 0700)
- if err != nil {
- panic(err)
- }
- err = os.Chmod(path, mode)
- if err != nil {
- panic(err)
- }
-}
-func createFifo(path string, mode fs.FileMode) {
- err := syscall.Mkfifo(path, 0600)
- if err != nil {
- panic(err)
- }
- err = os.Chmod(path, mode)
- if err != nil {
- panic(err)
- }
-}
-
-func currentUserAndGroup() (string, int, string, int) {
- u, err := user.Current()
- if err != nil {
- panic(err)
- }
- g, err := user.LookupGroupId(u.Gid)
- if err != nil {
- panic(err)
- }
- uid, err := strconv.Atoi(u.Uid)
- if err != nil {
- panic(err)
- }
- gid, err := strconv.Atoi(g.Gid)
- if err != nil {
- panic(err)
- }
- return u.Username, uid, g.Name, gid
-}