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


Golang FileMode.Perm方法代码示例

本文整理汇总了Golang中os.FileMode.Perm方法的典型用法代码示例。如果您正苦于以下问题:Golang FileMode.Perm方法的具体用法?Golang FileMode.Perm怎么用?Golang FileMode.Perm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os.FileMode的用法示例。


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

示例1: copyDir

func copyDir(src, dst string, mode os.FileMode) error {
	srcf, err := os.Open(src)
	if err != nil {
		return err
	}
	defer srcf.Close()
	if mode&0500 == 0 {
		// The source directory doesn't have write permission,
		// so give the new directory write permission anyway
		// so that we have permission to create its contents.
		// We'll make the permissions match at the end.
		mode |= 0500
	}
	if err := os.Mkdir(dst, mode.Perm()); err != nil {
		return err
	}
	for {
		names, err := srcf.Readdirnames(100)
		for _, name := range names {
			if err := Copy(filepath.Join(src, name), filepath.Join(dst, name)); err != nil {
				return err
			}
		}
		if err == io.EOF {
			break
		}
		if err != nil {
			return fmt.Errorf("error reading directory %q: %v", src, err)
		}
	}
	if err := os.Chmod(dst, mode.Perm()); err != nil {
		return err
	}
	return nil
}
开发者ID:juju,项目名称:utils,代码行数:35,代码来源:copy.go

示例2: permToACL

// permToACL - convert perm to meaningful ACL
func permToACL(mode os.FileMode) BucketACL {
	switch mode.Perm() {
	case os.FileMode(0700):
		return BucketACL("private")
	case os.FileMode(0500):
		return BucketACL("public-read")
	case os.FileMode(0777):
		return BucketACL("public-read-write")
	default:
		return BucketACL("private")
	}
}
开发者ID:zhujo01,项目名称:minio,代码行数:13,代码来源:fs-bucket.go

示例3: OpenFile

func (fs *memFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
	fs.mu.Lock()
	defer fs.mu.Unlock()

	dir, frag, err := fs.find("open", name)
	if err != nil {
		return nil, err
	}
	var n *memFSNode
	if dir == nil {
		// We're opening the root.
		if flag&(os.O_WRONLY|os.O_RDWR) != 0 {
			return nil, os.ErrPermission
		}
		n, frag = &fs.root, "/"

	} else {
		n = dir.children[frag]
		if flag&(os.O_SYNC|os.O_APPEND) != 0 {
			// memFile doesn't support these flags yet.
			return nil, os.ErrInvalid
		}
		if flag&os.O_CREATE != 0 {
			if flag&os.O_EXCL != 0 && n != nil {
				return nil, os.ErrExist
			}
			if n == nil {
				n = &memFSNode{
					mode: perm.Perm(),
				}
				dir.children[frag] = n
			}
		}
		if n == nil {
			return nil, os.ErrNotExist
		}
		if flag&(os.O_WRONLY|os.O_RDWR) != 0 && flag&os.O_TRUNC != 0 {
			n.mu.Lock()
			n.data = nil
			n.mu.Unlock()
		}
	}

	children := make([]os.FileInfo, 0, len(n.children))
	for cName, c := range n.children {
		children = append(children, c.stat(cName))
	}
	return &memFile{
		n:                n,
		nameSnapshot:     frag,
		childrenSnapshot: children,
	}, nil
}
开发者ID:tessavitabile,项目名称:logkeeper,代码行数:53,代码来源:file.go

示例4: posixMode

// posixMode() returns the posix specific  mode bits from Go's portable mode bits
//
// Copied from the syscallMode() function in file_posix.go in the Go source
func posixMode(i os.FileMode) (o uint32) {
	o |= uint32(i.Perm())
	if i&os.ModeSetuid != 0 {
		o |= syscall.S_ISUID
	}
	if i&os.ModeSetgid != 0 {
		o |= syscall.S_ISGID
	}
	if i&os.ModeSticky != 0 {
		o |= syscall.S_ISVTX
	}
	return
}
开发者ID:vbellur,项目名称:gogfapi,代码行数:16,代码来源:utils.go

示例5: WriteToFile

func (pb *Packbuilder) WriteToFile(name string, mode os.FileMode) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_packbuilder_write(pb.ptr, cname, C.uint(mode.Perm()), nil, nil)
	if ret != 0 {
		return MakeGitError(ret)
	}
	return nil
}
开发者ID:wid,项目名称:git2go,代码行数:13,代码来源:packbuilder.go

示例6: FileMode

// Given a FileMode from the os package, get it's permission bits
func FileMode(fm os.FileMode) PermissionBits {
	perm := PermissionBits(fm.Perm())

	if fm&os.ModeSetuid != 0 {
		perm.SetSetuid(true)
	}
	if fm&os.ModeSetgid != 0 {
		perm.SetSetgid(true)
	}
	if fm&os.ModeSticky != 0 {
		perm.SetSticky(true)
	}
	return perm
}
开发者ID:ChristianKniep,项目名称:swarmkit,代码行数:15,代码来源:permbits.go

示例7: syscallMode

// https://github.com/jnwhiteh/golang/blob/master/src/pkg/os/file_posix.go#L61
func syscallMode(i os.FileMode) (o uint32) {
	o |= uint32(i.Perm())
	if i&os.ModeSetuid != 0 {
		o |= syscall.S_ISUID
	}
	if i&os.ModeSetgid != 0 {
		o |= syscall.S_ISGID
	}
	if i&os.ModeSticky != 0 {
		o |= syscall.S_ISVTX
	}
	// No mapping for Go's ModeTemporary (plan9 only).
	return
}
开发者ID:2sidedfigure,项目名称:tail,代码行数:15,代码来源:winfile.go

示例8: OpenFile

func (fs *memFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
	var ret *memFile
	err := fs.walk("open", name, func(dir *memFSNode, frag string, final bool) error {
		if !final {
			return nil
		}
		if frag == "" {
			return os.ErrInvalid
		}
		if flag&(os.O_SYNC|os.O_APPEND) != 0 {
			return os.ErrInvalid
		}
		n := dir.children[frag]
		if flag&os.O_CREATE != 0 {
			if flag&os.O_EXCL != 0 && n != nil {
				return os.ErrExist
			}
			if n == nil {
				n = &memFSNode{
					name: frag,
					mode: perm.Perm(),
				}
				dir.children[frag] = n
			}
		}
		if n == nil {
			return os.ErrNotExist
		}
		if flag&(os.O_WRONLY|os.O_RDWR) != 0 && flag&os.O_TRUNC != 0 {
			n.mu.Lock()
			n.data = nil
			n.mu.Unlock()
		}

		children := make([]os.FileInfo, 0, len(n.children))
		for _, c := range n.children {
			children = append(children, c)
		}
		ret = &memFile{
			n:        n,
			children: children,
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	return ret, nil
}
开发者ID:pondyond,项目名称:leanote-all,代码行数:49,代码来源:file.go

示例9: Command

func Command(rootfsPath string, uid, gid int, mode os.FileMode, recreate bool, paths ...string) *exec.Cmd {
	flags := []string{
		name,
		"-rootfsPath", rootfsPath,
		"-uid", strconv.Itoa(uid),
		"-gid", strconv.Itoa(gid),
		"-perm", strconv.Itoa(int(mode.Perm())),
	}

	if recreate {
		flags = append(flags, "-recreate=true")
	}

	return reexec.Command(append(flags, paths...)...)
}
开发者ID:cloudfoundry,项目名称:guardian,代码行数:15,代码来源:prepare.go

示例10: osFileModeToFuseFileMode

// osFileModeToFuseFileMode converts a standard os.FileMode to the bit array used
// by the fuse package. Permissions, regular/dir modes, symlinks, and named pipes
// are the only bits that are converted.
func osFileModeToFuseFileMode(inMode os.FileMode) (outMode uint32) {
	if inMode.IsRegular() {
		outMode |= fuse.S_IFREG
	}
	if inMode.IsDir() {
		outMode |= fuse.S_IFDIR
	}
	if inMode&os.ModeSymlink == os.ModeSymlink {
		outMode |= fuse.S_IFLNK
	}
	if inMode&os.ModeNamedPipe == os.ModeNamedPipe {
		outMode |= fuse.S_IFIFO
	}
	outMode |= uint32(inMode.Perm())
	return
}
开发者ID:freakmac,项目名称:adbfs,代码行数:19,代码来源:util.go

示例11: Mkdir

func (fs *memFS) Mkdir(name string, perm os.FileMode) error {
	return fs.walk("mkdir", name, func(dir *memFSNode, frag string, final bool) error {
		if !final {
			return nil
		}
		if frag == "" {
			return os.ErrInvalid
		}
		if _, ok := dir.children[frag]; ok {
			return os.ErrExist
		}
		dir.children[frag] = &memFSNode{
			name:     frag,
			children: make(map[string]*memFSNode),
			mode:     perm.Perm() | os.ModeDir,
			modTime:  time.Now(),
		}
		return nil
	})
}
开发者ID:pondyond,项目名称:leanote-all,代码行数:20,代码来源:file.go

示例12: mknod

// mknod provides a shortcut for syscall.Mknod
func mknod(p string, mode os.FileMode, maj, min int) error {
	var (
		m   = syscallMode(mode.Perm())
		dev int
	)

	if mode&os.ModeDevice != 0 {
		dev = makedev(maj, min)

		if mode&os.ModeCharDevice != 0 {
			m |= syscall.S_IFCHR
		} else {
			m |= syscall.S_IFBLK
		}
	} else if mode&os.ModeNamedPipe != 0 {
		m |= syscall.S_IFIFO
	}

	return syscall.Mknod(p, m, dev)
}
开发者ID:tonistiigi,项目名称:continuity,代码行数:21,代码来源:devices_unix.go

示例13: copyFile

func copyFile(src, dst string, mode os.FileMode) error {
	srcf, err := os.Open(src)
	if err != nil {
		return err
	}
	defer srcf.Close()
	dstf, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode.Perm())
	if err != nil {
		return err
	}
	defer dstf.Close()
	// Make the actual permissions match the source permissions
	// even in the presence of umask.
	if err := os.Chmod(dstf.Name(), mode.Perm()); err != nil {
		return err
	}
	if _, err := io.Copy(dstf, srcf); err != nil {
		return fmt.Errorf("cannot copy %q to %q: %v", src, dst, err)
	}
	return nil
}
开发者ID:juju,项目名称:utils,代码行数:21,代码来源:copy.go

示例14: Mkdir

func (fs *memFS) Mkdir(name string, perm os.FileMode) error {
	fs.mu.Lock()
	defer fs.mu.Unlock()

	dir, frag, err := fs.find("mkdir", name)
	if err != nil {
		return err
	}
	if dir == nil {
		// We can't create the root.
		return os.ErrInvalid
	}
	if _, ok := dir.children[frag]; ok {
		return os.ErrExist
	}
	dir.children[frag] = &memFSNode{
		children: make(map[string]*memFSNode),
		mode:     perm.Perm() | os.ModeDir,
		modTime:  time.Now(),
	}
	return nil
}
开发者ID:tessavitabile,项目名称:logkeeper,代码行数:22,代码来源:file.go

示例15: PushFile

func (c *Client) PushFile(container string, p string, gid int, uid int, mode os.FileMode, buf io.ReadSeeker) error {
	query := url.Values{"path": []string{p}}
	uri := c.url(shared.APIVersion, "containers", container, "files") + "?" + query.Encode()

	req, err := http.NewRequest("POST", uri, buf)
	if err != nil {
		return err
	}
	req.Header.Set("User-Agent", shared.UserAgent)

	req.Header.Set("X-LXD-mode", fmt.Sprintf("%04o", mode.Perm()))
	req.Header.Set("X-LXD-uid", strconv.FormatUint(uint64(uid), 10))
	req.Header.Set("X-LXD-gid", strconv.FormatUint(uint64(gid), 10))

	raw, err := c.Http.Do(req)
	if err != nil {
		return err
	}

	_, err = HoistResponse(raw, Sync)
	return err
}
开发者ID:jameinel,项目名称:lxd,代码行数:22,代码来源:client.go


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