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


Golang syscall.Chmod函数代码示例

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


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

示例1: GetArtifact

func GetArtifact(destDir, source, checksum string, logger *log.Logger) (string, error) {
	if source == "" {
		return "", fmt.Errorf("Source url is empty in Artifact Getter")
	}
	u, err := url.Parse(source)
	if err != nil {
		return "", err
	}

	// if checksum is seperate, apply to source
	if checksum != "" {
		source = strings.Join([]string{source, fmt.Sprintf("checksum=%s", checksum)}, "?")
		logger.Printf("[DEBUG] client.getter: Applying checksum to Artifact Source URL, new url: %s", source)
	}

	artifactFile := filepath.Join(destDir, path.Base(u.Path))
	if err := gg.GetFile(artifactFile, source); err != nil {
		return "", fmt.Errorf("Error downloading artifact: %s", err)
	}

	// Add execution permissions to the newly downloaded artifact
	if runtime.GOOS != "windows" {
		if err := syscall.Chmod(artifactFile, 0755); err != nil {
			logger.Printf("[ERR] driver.raw_exec: Error making artifact executable: %s", err)
		}
	}
	return artifactFile, nil
}
开发者ID:bastiaanb,项目名称:nomad,代码行数:28,代码来源:getter.go

示例2: ChMod

/* ============================================================================================ */
func ChMod(filename string, mode int) bool {
	err := syscall.Chmod(filename, uint32(mode))
	if err == nil {
		return true
	}
	return false
}
开发者ID:PavelVershinin,项目名称:GoWeb,代码行数:8,代码来源:files.go

示例3: main

func main() {
	flag.Parse()
	if len(flag.Args()) < 2 {
		flag.PrintDefaults()
		log.Fatalf("usage: chmod mode filepath")
	}

	octval, err := strconv.ParseUint(flag.Args()[0], 8, 32)
	if err != nil {
		log.Fatalf("Unable to decode mode. Please use an octal value. arg was %s, err was %v", flag.Args()[0], err)
	} else if octval > 0777 {
		log.Fatalf("Invalid octal value. Value larger than 777, was %o", octval)
	}

	mode := uint32(octval)

	var errors string
	for _, arg := range flag.Args()[1:] {
		if err := syscall.Chmod(arg, mode); err != nil {
			errors += fmt.Sprintf("Unable to chmod, filename was %s, err was %v\n", arg, err)
		}
	}
	if errors != "" {
		log.Fatalf(errors)
	}

}
开发者ID:u-root,项目名称:u-root,代码行数:27,代码来源:chmod.go

示例4: writeMetadata

func (inode *SpecialInode) writeMetadata(name string) error {
	if err := os.Lchown(name, int(inode.Uid), int(inode.Gid)); err != nil {
		return err
	}
	if err := syscall.Chmod(name, uint32(inode.Mode)); err != nil {
		return err
	}
	t := time.Unix(inode.MtimeSeconds, int64(inode.MtimeNanoSeconds))
	return os.Chtimes(name, t, t)
}
开发者ID:JohnTheodore,项目名称:Dominator,代码行数:10,代码来源:write.go

示例5: Chmod

// Chmod implements pathfs.Filesystem.
func (fs *FS) Chmod(path string, mode uint32, context *fuse.Context) (code fuse.Status) {
	if fs.isFiltered(path) {
		return fuse.EPERM
	}
	cPath, err := fs.getBackingPath(path)
	if err != nil {
		return fuse.ToStatus(err)
	}
	// os.Chmod goes through the "syscallMode" translation function that messes
	// up the suid and sgid bits. So use syscall.Chmod directly.
	err = syscall.Chmod(cPath, mode)
	return fuse.ToStatus(err)
}
开发者ID:rfjakob,项目名称:gocryptfs,代码行数:14,代码来源:fs.go

示例6: write

func (inode *DirectoryInode) write(name string) error {
	if inode.make(name) != nil {
		os.RemoveAll(name)
		if err := inode.make(name); err != nil {
			return err
		}
	}
	if err := os.Lchown(name, int(inode.Uid), int(inode.Gid)); err != nil {
		return err
	}
	if inode.Mode & ^modePerm != syscall.S_IFDIR {
		if err := syscall.Chmod(name, uint32(inode.Mode)); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:JohnTheodore,项目名称:Dominator,代码行数:17,代码来源:write.go

示例7: createTarFile

func createTarFile(path, extractDir string, hdr *tar.Header, reader *tar.Reader) error {
	switch hdr.Typeflag {
	case tar.TypeDir:
		// Create directory unless it exists as a directory already.
		// In that case we just want to merge the two
		if fi, err := os.Lstat(path); !(err == nil && fi.IsDir()) {
			if err := os.Mkdir(path, os.FileMode(hdr.Mode)); err != nil {
				return err
			}
		}

	case tar.TypeReg, tar.TypeRegA:
		// Source is regular file
		file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, os.FileMode(hdr.Mode))
		if err != nil {
			return err
		}
		if _, err := io.Copy(file, reader); err != nil {
			file.Close()
			return err
		}
		file.Close()

	case tar.TypeBlock, tar.TypeChar, tar.TypeFifo:
		mode := uint32(hdr.Mode & 07777)
		switch hdr.Typeflag {
		case tar.TypeBlock:
			mode |= syscall.S_IFBLK
		case tar.TypeChar:
			mode |= syscall.S_IFCHR
		case tar.TypeFifo:
			mode |= syscall.S_IFIFO
		}

		if err := syscall.Mknod(path, mode, int(mkdev(hdr.Devmajor, hdr.Devminor))); err != nil {
			return err
		}

	case tar.TypeLink:
		if err := os.Link(filepath.Join(extractDir, hdr.Linkname), path); err != nil {
			return err
		}

	case tar.TypeSymlink:
		if err := os.Symlink(hdr.Linkname, path); err != nil {
			return err
		}

	case tar.TypeXGlobalHeader:
		utils.Debugf("PAX Global Extended Headers found and ignored")
		return nil

	default:
		return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag)
	}

	if err := syscall.Lchown(path, hdr.Uid, hdr.Gid); err != nil {
		return err
	}

	// There is no LChmod, so ignore mode for symlink. Also, this
	// must happen after chown, as that can modify the file mode
	if hdr.Typeflag != tar.TypeSymlink {
		if err := syscall.Chmod(path, uint32(hdr.Mode&07777)); err != nil {
			return err
		}
	}

	ts := []syscall.Timespec{timeToTimespec(hdr.AccessTime), timeToTimespec(hdr.ModTime)}
	// syscall.UtimesNano doesn't support a NOFOLLOW flag atm, and
	if hdr.Typeflag != tar.TypeSymlink {
		if err := syscall.UtimesNano(path, ts); err != nil {
			return err
		}
	} else {
		if err := LUtimesNano(path, ts); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:Nerdness,项目名称:docker,代码行数:81,代码来源:archive.go

示例8: SetAttr


//.........这里部分代码省略.........
			constor.error("Fstat failed on %s : %s", F.id, err)
			return fuse.ToStatus(err)
		}
		attr := (*fuse.Attr)(&out.Attr)
		attr.FromStat(&stat)
		attr.Ino = idtoino(inode.id)
		return fuse.OK
	}

	if inode.layer == -1 {
		return fuse.ENOENT
	}

	if inode.layer != 0 {
		err = constor.copyup(inode)
		if err != nil {
			constor.error("copyup failed for %s - %s", inode.id, err)
			return fuse.ToStatus(err)
		}
	}

	stat := syscall.Stat_t{}
	path := constor.getPath(0, inode.id)

	// just to satisfy PJD tests
	if input.Valid == 0 {
		err = syscall.Lchown(path, uid, gid)
		if err != nil {
			return fuse.ToStatus(err)
		}
	}
	if input.Valid&fuse.FATTR_MODE != 0 {
		permissions := uint32(07777) & input.Mode
		err = syscall.Chmod(path, permissions)
		if err != nil {
			constor.error("Lchmod failed on %s - %d : %s", path, permissions, err)
			return fuse.ToStatus(err)
		}
	}
	if input.Valid&(fuse.FATTR_UID) != 0 {
		uid = int(input.Uid)
	}
	if input.Valid&(fuse.FATTR_GID) != 0 {
		gid = int(input.Gid)
	}

	if input.Valid&(fuse.FATTR_UID|fuse.FATTR_GID) != 0 {
		constor.log("%s %d %d", path, uid, gid)
		err = syscall.Lchown(path, uid, gid)
		if err != nil {
			constor.error("Lchown failed on %s - %d %d : %s", path, uid, gid, err)
			return fuse.ToStatus(err)
		}
	}
	if input.Valid&fuse.FATTR_SIZE != 0 {
		err = syscall.Truncate(path, int64(input.Size))
		if err != nil {
			constor.error("Truncate failed on %s - %d : %s", path, input.Size, err)
			return fuse.ToStatus(err)
		}
	}
	if input.Valid&(fuse.FATTR_ATIME|fuse.FATTR_MTIME|fuse.FATTR_ATIME_NOW|fuse.FATTR_MTIME_NOW) != 0 {
		now := time.Now()
		var atime *time.Time
		var mtime *time.Time
开发者ID:krishnasrinivas,项目名称:confs,代码行数:66,代码来源:main.go

示例9: Chmod

// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
func Chmod(name string, mode int) Error {
	if e := syscall.Chmod(name, mode); e != 0 {
		return &PathError{"chmod", name, Errno(e)}
	}
	return nil
}
开发者ID:lougxing,项目名称:golang-china,代码行数:8,代码来源:file.go

示例10: Chmod

// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
func Chmod(name string, mode uint32) error {
	if e := syscall.Chmod(name, mode); iserror(e) {
		return &PathError{"chmod", name, Errno(e)}
	}
	return nil
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:8,代码来源:file_posix.go

示例11: main

func main() {
	host := os.Getenv("ISUCON5_DB_HOST")
	if host == "" {
		host = "localhost"
	}
	portstr := os.Getenv("ISUCON5_DB_PORT")
	if portstr == "" {
		portstr = "3306"
	}
	port, err := strconv.Atoi(portstr)
	if err != nil {
		log.Fatalf("Failed to read DB port number from an environment variable ISUCON5_DB_PORT.\nError: %s", err.Error())
	}
	user := os.Getenv("ISUCON5_DB_USER")
	if user == "" {
		user = "root"
	}
	password := os.Getenv("ISUCON5_DB_PASSWORD")
	dbname := os.Getenv("ISUCON5_DB_NAME")
	if dbname == "" {
		dbname = "isucon5q"
	}
	ssecret := os.Getenv("ISUCON5_SESSION_SECRET")
	if ssecret == "" {
		ssecret = "beermoris"
	}

	db, err = sql.Open("mysql", user+":"+password+"@tcp("+host+":"+strconv.Itoa(port)+")/"+dbname+"?loc=Local&parseTime=true")
	if err != nil {
		log.Fatalf("Failed to connect to DB: %s.", err.Error())
	}
	defer db.Close()

	store = sessions.NewCookieStore([]byte(ssecret))

	r := mux.NewRouter()

	l := r.Path("/login").Subrouter()
	l.Methods("GET").HandlerFunc(myHandler(GetLogin))
	l.Methods("POST").HandlerFunc(myHandler(PostLogin))
	r.Path("/logout").Methods("GET").HandlerFunc(myHandler(GetLogout))

	p := r.Path("/profile/{account_name}").Subrouter()
	p.Methods("GET").HandlerFunc(myHandler(GetProfile))
	p.Methods("POST").HandlerFunc(myHandler(PostProfile))

	d := r.PathPrefix("/diary").Subrouter()
	d.HandleFunc("/entries/{account_name}", myHandler(ListEntries)).Methods("GET")
	d.HandleFunc("/entry", myHandler(PostEntry)).Methods("POST")
	d.HandleFunc("/entry/{entry_id}", myHandler(GetEntry)).Methods("GET")

	d.HandleFunc("/comment/{entry_id}", myHandler(PostComment)).Methods("POST")

	r.HandleFunc("/footprints", myHandler(GetFootprints)).Methods("GET")

	r.HandleFunc("/friends", myHandler(GetFriends)).Methods("GET")
	r.HandleFunc("/friends/{account_name}", myHandler(PostFriends)).Methods("POST")

	r.HandleFunc("/initialize", myHandler(GetInitialize))
	r.HandleFunc("/", myHandler(GetIndex))
	r.PathPrefix("/").Handler(http.FileServer(http.Dir("../static")))

	//log.Fatal(http.ListenAndServe(":8080", r))
	listen, _ := net.Listen("unix", "/run/sock-shared/isuxi.go.sock")
	syscall.Chmod("/run/sock-shared/isuxi.go.sock", 0777)
	log.Fatal(http.Serve(listen, r))
}
开发者ID:gam0022,项目名称:isucon5q,代码行数:67,代码来源:app.go

示例12: Chmod

func (k *PosixKernel) Chmod(path string, mode uint32) uint64 {
	return Errno(syscall.Chmod(path, mode))
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:3,代码来源:io.go

示例13: copyup

func (constor *Constor) copyup(inode *Inode) error {
	constor.log("%s", inode.id)
	if inode.layer == 0 {
		return nil
	}
	src := constor.getPath(inode.layer, inode.id)
	if src == "" {
		return syscall.EIO
	}
	dst := constor.getPath(0, inode.id)
	if dst == "" {
		return syscall.EIO
	}
	fi, err := os.Lstat(src)
	if err != nil {
		return err
	}
	if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
		linkName, err := os.Readlink(src)
		if err != nil {
			return err
		}
		err = os.Symlink(linkName, dst)
		if err != nil {
			return err
		}
	} else if fi.Mode()&os.ModeDir == os.ModeDir {
		err := os.Mkdir(dst, fi.Mode())
		if err != nil {
			return err
		}
	} else {
		in, err := os.Open(src)
		if err != nil {
			return err
		}
		defer in.Close()
		out, err := os.Create(dst)
		if err != nil {
			return err
		}
		defer out.Close()
		_, err = io.Copy(out, in)
		if err != nil {
			return err
		}
		err = out.Close()
		if err != nil {
			return err
		}
	}
	stat := syscall.Stat_t{}
	if err = syscall.Lstat(src, &stat); err != nil {
		return err
	}
	if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
		if err = syscall.Chmod(dst, stat.Mode); err != nil {
			return err
		}
	}
	if err = syscall.Lchown(dst, int(stat.Uid), int(stat.Gid)); err != nil {
		return err
	}
	links, err := Lgetxattr(src, LINKSXATTR)
	if err == nil && len(links) > 0 {
		err := Lsetxattr(dst, LINKSXATTR, links, 0)
		if err != nil {
			return err
		}
	}

	if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
		if err = syscall.UtimesNano(dst, []syscall.Timespec{stat.Atim, stat.Mtim}); err != nil {
			return err
		}
	}
	inode.layer = 0
	constor.log("done", inode.id)
	return nil
}
开发者ID:krishnasrinivas,项目名称:confs,代码行数:80,代码来源:helpers.go

示例14: Chmod

// Given a filepath, set it's permission bits directly
func Chmod(filepath string, b PermissionBits) error {
	if e := syscall.Chmod(filepath, syscallMode(b)); e != nil {
		return &os.PathError{"chmod", filepath, e}
	}
	return nil
}
开发者ID:ChristianKniep,项目名称:swarmkit,代码行数:7,代码来源:permbits.go

示例15: SetAttr

func (constor *Constor) SetAttr(input *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
	constor.log("%d %d", input.NodeId, input.Valid)
	var err error
	uid := -1
	gid := -1

	// if ((input.Valid & fuse.FATTR_FH) !=0) && ((input.Valid & (fuse.FATTR_ATIME | fuse.FATTR_MTIME)) == 0) {
	if ((input.Valid & fuse.FATTR_FH) != 0) && ((input.Valid & fuse.FATTR_SIZE) != 0) {
		ptr := uintptr(input.Fh)
		F := constor.getfd(ptr)
		if F == nil {
			constor.error("F == nil")
			return fuse.EIO
		}
		if F.layer != 0 {
			constor.error("layer not 0")
			return fuse.EIO
		}
		constor.log("Ftruncate %d", ptr)
		err := syscall.Ftruncate(F.fd, int64(input.Size))
		if err != nil {
			constor.error("%s", err)
			return fuse.ToStatus(err)
		}
		stat := syscall.Stat_t{}
		err = syscall.Fstat(F.fd, &stat)
		if err != nil {
			constor.error("%s", err)
			return fuse.ToStatus(err)
		}
		attr := (*fuse.Attr)(&out.Attr)
		attr.FromStat(&stat)
		attr.Ino = input.NodeId
		return fuse.OK
	}

	inode, err := constor.inodemap.findInode(input.NodeId)
	if err != nil {
		return fuse.ToStatus(err)
	}
	if inode.layer != 0 {
		err = constor.copyup(inode)
		if err != nil {
			constor.log("%s", err)
			return fuse.ToStatus(err)
		}
	}

	stat := syscall.Stat_t{}
	path, err := constor.dentrymap.getPath(input.NodeId)
	if err != nil {
		constor.log("%s", err)
		return fuse.ToStatus(err)
	}
	pathl := Path.Join(constor.layers[0], path)

	// just to satisfy PJD tests
	if input.Valid == 0 {
		err = os.Lchown(pathl, uid, gid)
		if err != nil {
			return fuse.ToStatus(err)
		}
	}
	if input.Valid&fuse.FATTR_MODE != 0 {
		permissions := uint32(07777) & input.Mode
		err = syscall.Chmod(pathl, permissions)
		if err != nil {
			return fuse.ToStatus(err)
		}
	}
	if input.Valid&(fuse.FATTR_UID) != 0 {
		uid = int(input.Uid)
	}
	if input.Valid&(fuse.FATTR_GID) != 0 {
		gid = int(input.Gid)
	}

	if input.Valid&(fuse.FATTR_UID|fuse.FATTR_GID) != 0 {
		constor.log("%s %d %d", pathl, uid, gid)
		err = os.Lchown(pathl, uid, gid)
		if err != nil {
			return fuse.ToStatus(err)
		}
	}
	if input.Valid&fuse.FATTR_SIZE != 0 {
		err = os.Truncate(pathl, int64(input.Size))
		if err != nil {
			return fuse.ToStatus(err)
		}
	}
	if input.Valid&(fuse.FATTR_ATIME|fuse.FATTR_MTIME|fuse.FATTR_ATIME_NOW|fuse.FATTR_MTIME_NOW) != 0 {
		now := time.Now()
		var atime *time.Time
		var mtime *time.Time

		if input.Valid&fuse.FATTR_ATIME_NOW != 0 {
			atime = &now
		} else {
			t := time.Unix(int64(input.Atime), int64(input.Atimensec))
			atime = &t
//.........这里部分代码省略.........
开发者ID:krishnasrinivas,项目名称:constor,代码行数:101,代码来源:main.go


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