当前位置: 首页>>代码示例>>Golang>>正文


Golang os.Getgid函数代码示例

本文整理汇总了Golang中os.Getgid函数的典型用法代码示例。如果您正苦于以下问题:Golang Getgid函数的具体用法?Golang Getgid怎么用?Golang Getgid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Getgid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestLink

func TestLink(t *testing.T) {
	ino := maggiefs.NewInode(0, maggiefs.FTYPE_REG, 0755, uint32(os.Getuid()), uint32(os.Getgid()))
	id, err := testCluster.Names.AddInode(ino)
	if err != nil {
		panic(err)
	}
	ino.Inodeid = id

	ino2 := maggiefs.NewInode(0, maggiefs.FTYPE_REG, 0755, uint32(os.Getuid()), uint32(os.Getgid()))
	id, err = testCluster.Names.AddInode(ino)
	if err != nil {
		panic(err)
	}
	ino2.Inodeid = id

	// test normal link
	fmt.Println("linking")
	err = testCluster.Names.Link(ino.Inodeid, ino2.Inodeid, "name", true)
	if err != nil {
		panic(err)
	}
	ino, err = testCluster.Names.GetInode(ino.Inodeid)
	if err != nil {
		panic(err)
	}
	if ino.Children["name"].Inodeid != ino2.Inodeid {
		t.Fatalf("Didn't link properly!")
	}
	// test an unforced attempt to overwrite

	// test overwriting forced

}
开发者ID:jbooth,项目名称:maggiefs,代码行数:33,代码来源:nameserver_test.go

示例2: Attr

// Attr returns the attributes of a given node.
func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error {
	log.Debug("Node attr")
	if s.cached == nil {
		if err := s.loadData(); err != nil {
			return fmt.Errorf("readonly: loadData() failed: %s", err)
		}
	}
	switch s.cached.GetType() {
	case ftpb.Data_Directory:
		a.Mode = os.ModeDir | 0555
		a.Uid = uint32(os.Getuid())
		a.Gid = uint32(os.Getgid())
	case ftpb.Data_File:
		size := s.cached.GetFilesize()
		a.Mode = 0444
		a.Size = uint64(size)
		a.Blocks = uint64(len(s.Nd.Links))
		a.Uid = uint32(os.Getuid())
		a.Gid = uint32(os.Getgid())
	case ftpb.Data_Raw:
		a.Mode = 0444
		a.Size = uint64(len(s.cached.GetData()))
		a.Blocks = uint64(len(s.Nd.Links))
		a.Uid = uint32(os.Getuid())
		a.Gid = uint32(os.Getgid())
	case ftpb.Data_Symlink:
		a.Mode = 0777 | os.ModeSymlink
		a.Size = uint64(len(s.cached.GetData()))
		a.Uid = uint32(os.Getuid())
		a.Gid = uint32(os.Getgid())
	default:
		return fmt.Errorf("Invalid data type - %s", s.cached.GetType())
	}
	return nil
}
开发者ID:yanghongkjxy,项目名称:go-ipfs,代码行数:36,代码来源:readonly_unix.go

示例3: Test_l_File_Link2

// Test running 'ls -l' with a symlink 'b' pointing to a file 'a'
func Test_l_File_Link2(t *testing.T) {
	setup_test_dir("l_File_Link2")

	time_now := time.Now()
	size := 13
	path := "a"
	_mkfile2(path, 0600, os.Getuid(), os.Getgid(), size, time_now)

	_mklink(path, "b")

	var output_buffer bytes.Buffer
	args := []string{"-l", "--nocolor"}
	ls_err := ls(&output_buffer, args, tw)

	output := clean_output_buffer(output_buffer)

	// remove the permissions string from each file listing
	output_line_split := strings.Split(output, "\n")
	output_noperms := ""
	for _, l := range output_line_split {
		output_line_split_noperms := strings.Split(l, " ")[1:]
		output_line_noperms := strings.Join(output_line_split_noperms, " ")
		if len(output_noperms) == 0 {
			output_noperms = output_line_noperms
		} else {
			output_noperms = output_noperms + "\n" + output_line_noperms
		}
	}

	var owner string
	owner_lookup, err := user.LookupId(fmt.Sprintf("%d", os.Getuid()))
	if err != nil {
		owner = user_map[int(os.Getuid())]
	} else {
		owner = owner_lookup.Username
	}

	group := group_map[os.Getgid()]

	expected := fmt.Sprintf(
		"1 %s %s %d %s %02d %02d:%02d a\n1 %s %s 1 %s %02d %02d:%02d b -> %s",
		owner,
		group,
		size,
		time_now.Month().String()[0:3],
		time_now.Day(),
		time_now.Hour(),
		time_now.Minute(),
		owner,
		group,
		time_now.Month().String()[0:3],
		time_now.Day(),
		time_now.Hour(),
		time_now.Minute(),
		path)

	check_output(t, output_noperms, expected)
	check_error_nil(t, ls_err)
}
开发者ID:yangzhao28,项目名称:ls,代码行数:60,代码来源:ls_test.go

示例4: Test_LS_COLORS_orphan_link

// Test LS_COLORS with an orphan link
func Test_LS_COLORS_orphan_link(t *testing.T) {
	setup_test_dir("LS_COLORS_orphan_link")

	time_now := time.Now()

	_mkfile2("a", 0600, os.Getuid(), os.Getgid(), 8, time_now)
	_mklink("a", "b")
	_rm("a")

	os.Setenv("LS_COLORS", default_LS_COLORS)

	var output_buffer bytes.Buffer
	args := []string{"-l"}
	ls_err := ls(&output_buffer, args, tw)

	output := clean_output_buffer(output_buffer)
	// remove the permissions string from the output
	output_noperms := strings.Join(strings.Split(output, " ")[1:], " ")

	var owner string
	owner_lookup, err := user.LookupId(fmt.Sprintf("%d", os.Getuid()))
	if err != nil {
		owner = user_map[int(os.Getuid())]
	} else {
		owner = owner_lookup.Username
	}

	group := group_map[os.Getgid()]

	// link info
	link_info, err := os.Lstat("b")
	if err != nil {
		t.Fatalf("error checking the symlink")
	}

	expected := fmt.Sprintf("1 %s %s %d %s %02d %02d:%02d %sb%s -> %sa%s",
		owner,
		group,
		link_info.Size(),
		time_now.Month().String()[0:3],
		time_now.Day(),
		time_now.Hour(),
		time_now.Minute(),
		"\x1b[40;31;01m",
		"\x1b[0m",
		"\x1b[01;05;37;41m",
		"\x1b[0m")

	check_output(t, output_noperms, expected)
	check_error_nil(t, ls_err)
}
开发者ID:yangzhao28,项目名称:ls,代码行数:52,代码来源:ls_test.go

示例5: DirMeta

func (this *mapbe) DirMeta() (Meta, error) {
	return Meta{
		Perm: 0755,
		Uid:  uint32(os.Getuid()),
		Gid:  uint32(os.Getgid()),
	}, nil
}
开发者ID:conductant,项目名称:gohm,代码行数:7,代码来源:map.go

示例6: Attr

// Attr returns the attributes of a given node.
func (d *Directory) Attr(ctx context.Context, a *fuse.Attr) error {
	log.Debug("Directory Attr")
	a.Mode = os.ModeDir | 0555
	a.Uid = uint32(os.Getuid())
	a.Gid = uint32(os.Getgid())
	return nil
}
开发者ID:palkeo,项目名称:go-ipfs,代码行数:8,代码来源:ipns_unix.go

示例7: Attr

func (n *mutFile) Attr() fuse.Attr {
	// TODO: don't grab n.mu three+ times in here.
	var mode os.FileMode = 0600 // writable

	n.mu.Lock()
	size := n.size
	var blocks uint64
	if size > 0 {
		blocks = uint64(size)/512 + 1
	}
	inode := n.permanode.Sum64()
	if n.symLink {
		mode |= os.ModeSymlink
	}
	n.mu.Unlock()

	return fuse.Attr{
		Inode:  inode,
		Mode:   mode,
		Uid:    uint32(os.Getuid()),
		Gid:    uint32(os.Getgid()),
		Size:   uint64(size),
		Blocks: blocks,
		Mtime:  n.modTime(),
		Atime:  n.accessTime(),
		Ctime:  serverStart,
		Crtime: serverStart,
	}
}
开发者ID:JayBlaze420,项目名称:camlistore,代码行数:29,代码来源:mut.go

示例8: populateAttr

// populateAttr should only be called once n.ss is known to be set and
// non-nil
func (n *node) populateAttr() error {
	ss := n.ss

	n.attr.Mode = ss.FileMode()

	if n.fs.IgnoreOwners {
		n.attr.Uid = uint32(os.Getuid())
		n.attr.Gid = uint32(os.Getgid())
		executeBit := n.attr.Mode & 0100
		n.attr.Mode = (n.attr.Mode ^ n.attr.Mode.Perm()) & 0400 & executeBit
	} else {
		n.attr.Uid = uint32(ss.MapUid())
		n.attr.Gid = uint32(ss.MapGid())
	}

	// TODO: inode?

	n.attr.Mtime = ss.ModTime()

	switch ss.Type {
	case "file":
		n.attr.Size = ss.SumPartsSize()
		n.attr.Blocks = 0 // TODO: set?
	case "directory":
		// Nothing special? Just prevent default case.
	case "symlink":
		// Nothing special? Just prevent default case.
	default:
		log.Printf("unknown attr ss.Type %q in populateAttr", ss.Type)
	}
	return nil
}
开发者ID:t3rm1n4l,项目名称:camlistore,代码行数:34,代码来源:fs.go

示例9: newTestTar

func newTestTar(entries []*testTarEntry, dir string) (string, error) {
	t, err := ioutil.TempFile(dir, "tar")
	if err != nil {
		return "", err
	}
	defer t.Close()
	tw := tar.NewWriter(t)
	for _, entry := range entries {
		// Add default mode
		if entry.header.Mode == 0 {
			if entry.header.Typeflag == tar.TypeDir {
				entry.header.Mode = 0755
			} else {
				entry.header.Mode = 0644
			}
		}
		// Add calling user uid and gid or tests will fail
		entry.header.Uid = os.Getuid()
		entry.header.Gid = os.Getgid()
		if err := tw.WriteHeader(entry.header); err != nil {
			return "", err
		}
		if _, err := io.WriteString(tw, entry.contents); err != nil {
			return "", err
		}
	}
	if err := tw.Close(); err != nil {
		return "", err
	}
	return t.Name(), nil
}
开发者ID:krnowak,项目名称:appc-spec,代码行数:31,代码来源:acirenderer_test.go

示例10: TestNewFileCreation

func TestNewFileCreation(t *testing.T) {
	Convey("Given a file path", t, func() {
		fname := filepath.Join(os.TempDir(), "__test_filepath")

		Convey("It should create an empty file", func() {
			err := file.New(fname)
			So(err, ShouldBeNil)
			defer os.Remove(fname)

			_, err = os.Stat(fname)
			So(err, ShouldBeNil)
		})

		Convey("With optional argument Contents", func() {
			c := "This is a file with text in it.\n"
			Convey("It should create a new file with the given contents", func() {
				err := file.New(fname, file.Contents(c))
				So(err, ShouldBeNil)
				defer os.Remove(fname)

				out, err := ioutil.ReadFile(fname)

				So(err, ShouldBeNil)
				So(string(out), ShouldEqual, c)
			})
		})

		Convey("With optional argument Permissions", func() {
			p := os.FileMode(0700)

			Convey("It should create a new file with the same permissions", func() {
				err := file.New(fname, file.Permissions(p))
				So(err, ShouldBeNil)
				defer os.Remove(fname)
				fi, err := os.Lstat(fname)

				So(err, ShouldBeNil)
				So(fi.Mode(), ShouldEqual, p)
			})
		})

		Convey("With optional argument User ID and/or Group ID", func() {
			userID, groupID := os.Getuid(), os.Getgid()

			Convey("It should create a new file belonging to given IDs", func() {
				err := file.New(fname, file.UID(userID), file.GID(groupID))
				So(err, ShouldBeNil)
				defer os.Remove(fname)
				fi, err := os.Lstat(fname)
				So(err, ShouldBeNil)

				uid := fi.Sys().(*syscall.Stat_t).Uid
				So(uid, ShouldEqual, userID)

				gid := fi.Sys().(*syscall.Stat_t).Gid
				So(gid, ShouldEqual, groupID)
			})
		})
	})
}
开发者ID:maxamillion,项目名称:flamingo,代码行数:60,代码来源:file_test.go

示例11: changePermissions

func changePermissions(path string) error {
	var uid, gid int
	var err error

	suid := os.Getenv("SUDO_UID")
	if suid != "" {
		uid, err = strconv.Atoi(suid)
		if err != nil {
			return err
		}
	} else {
		uid = os.Getuid()
	}

	sgid := os.Getenv("SUDO_GID")
	if sgid != "" {
		gid, err = strconv.Atoi(sgid)
		if err != nil {
			return err
		}
	} else {
		gid = os.Getgid()
	}

	return os.Chown(path, uid, gid)
}
开发者ID:dunkelstern,项目名称:dlite,代码行数:26,代码来源:disk.go

示例12: Attr

func (n *rootsDir) Attr() fuse.Attr {
	return fuse.Attr{
		Mode: os.ModeDir | n.dirMode(),
		Uid:  uint32(os.Getuid()),
		Gid:  uint32(os.Getgid()),
	}
}
开发者ID:kdevroede,项目名称:camlistore,代码行数:7,代码来源:roots.go

示例13: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	listener, err := reuseport.NewReusablePortListener("tcp4", "localhost:8881")
	if err != nil {
		panic(err)

	}
	defer listener.Close()

	server := &http.Server{}
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Println(os.Getgid())
		go func() {
			cmd := exec.Command("./server")
			cmd.Start()
			log.Println("-------start")
			time.Sleep(18 * time.Second)
			log.Println("-------end")
			cmd.Process.Kill()
			cmd.Wait()
		}()
		fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path))
	})

	panic(server.Serve(listener))

}
开发者ID:needkane,项目名称:qiniu,代码行数:28,代码来源:reuse.go

示例14: newDirFromSnapshot

func newDirFromSnapshot(repo *repository.Repository, snapshot SnapshotWithId, ownerIsRoot bool) (*dir, error) {
	tree, err := restic.LoadTree(repo, *snapshot.Tree)
	if err != nil {
		return nil, err
	}
	items := make(map[string]*restic.Node)
	for _, n := range tree.Nodes {
		nodes, err := replaceSpecialNodes(repo, n)
		if err != nil {
			return nil, err
		}

		for _, node := range nodes {
			items[node.Name] = node
		}
	}

	return &dir{
		repo: repo,
		node: &restic.Node{
			UID:        uint32(os.Getuid()),
			GID:        uint32(os.Getgid()),
			AccessTime: snapshot.Time,
			ModTime:    snapshot.Time,
			ChangeTime: snapshot.Time,
			Mode:       os.ModeDir | 0555,
		},
		items:       items,
		inode:       inodeFromBackendId(snapshot.ID),
		ownerIsRoot: ownerIsRoot,
	}, nil
}
开发者ID:fawick,项目名称:restic,代码行数:32,代码来源:dir.go

示例15: OpenRuntime

func OpenRuntime(file string, flag int) (*os.File, error) {
	// TODO: Make sure that the runtime directory is only readable by the user.
	_, err := os.Stat(RuntimeDir)
	if err != nil {
		if os.IsNotExist(err) {
			err = os.MkdirAll(RuntimeDir, os.ModeDir|0700)
			if err != nil {
				return nil, err
			}
			_, err = os.Stat(RuntimeDir)
			if err != nil {
				// This really should never happen, but you never know!
				return nil, err
			}
		} else {
			return nil, err
		}
	}

	err = os.Chown(RuntimeDir, os.Getuid(), os.Getgid())
	if err != nil {
		return nil, err
	}

	return open(UserRuntime(file), flag)
}
开发者ID:goulash,项目名称:xdg,代码行数:26,代码来源:xdg.go


注:本文中的os.Getgid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。