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


Golang FileInfo.Permission方法代码示例

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


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

示例1: NewCommonFileMap

func NewCommonFileMap(fileName string, fi *os.FileInfo) map[string]interface{} {
	m := newCamliMap(1, "" /* no type yet */)

	lastSlash := strings.LastIndex(fileName, "/")
	baseName := fileName[lastSlash+1:]
	if isValidUtf8(baseName) {
		m["fileName"] = baseName
	} else {
		m["fileNameBytes"] = []uint8(baseName)
	}

	// Common elements (from file-common.txt)
	m["unixPermission"] = fmt.Sprintf("0%o", fi.Permission())
	if fi.Uid != -1 {
		m["unixOwnerId"] = fi.Uid
		if user := getUserFromUid(fi.Uid); user != "" {
			m["unixOwner"] = user
		}
	}
	if fi.Gid != -1 {
		m["unixGroupId"] = fi.Gid
		if group := getGroupFromGid(fi.Gid); group != "" {
			m["unixGroup"] = group
		}
	}
	if mtime := fi.Mtime_ns; mtime != 0 {
		m["unixMtime"] = rfc3339FromNanos(mtime)
	}
	// Include the ctime too, if it differs.
	if ctime := fi.Ctime_ns; ctime != 0 && fi.Mtime_ns != fi.Ctime_ns {
		m["unixCtime"] = rfc3339FromNanos(ctime)
	}

	return m
}
开发者ID:marsch,项目名称:camlistore,代码行数:35,代码来源:schema.go

示例2: NewCommonFileMap

func NewCommonFileMap(fileName string, fi *os.FileInfo) map[string]interface{} {
	m := NewCommonFilenameMap(fileName)
	// Common elements (from file-common.txt)
	if !fi.IsSymlink() {
		m["unixPermission"] = fmt.Sprintf("0%o", fi.Permission())
	}
	if fi.Uid != -1 {
		m["unixOwnerId"] = fi.Uid
		if user := getUserFromUid(fi.Uid); user != "" {
			m["unixOwner"] = user
		}
	}
	if fi.Gid != -1 {
		m["unixGroupId"] = fi.Gid
		if group := getGroupFromGid(fi.Gid); group != "" {
			m["unixGroup"] = group
		}
	}
	if mtime := fi.Mtime_ns; mtime != 0 {
		m["unixMtime"] = RFC3339FromNanos(mtime)
	}
	// Include the ctime too, if it differs.
	if ctime := fi.Ctime_ns; ctime != 0 && fi.Mtime_ns != fi.Ctime_ns {
		m["unixCtime"] = RFC3339FromNanos(ctime)
	}

	return m
}
开发者ID:ipeet,项目名称:camlistore,代码行数:28,代码来源:schema.go

示例3: SetRequestMetaData

func (p *Propolis) SetRequestMetaData(req *http.Request, info *os.FileInfo) {
	// file permissions: grant "public-read" if the file grants world read permission
	if info.Permission()&s_iroth != 0 {
		req.Header.Set("X-Amz-Acl", acl_public)
	} else {
		req.Header.Set("X-Amz-Acl", acl_private)
	}

	// user id: store the numeric and symbolic names
	user, err := user.LookupId(info.Uid)
	if err != nil {
		req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d", info.Uid))
	} else {
		req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d (%s)", info.Uid, user.Username))
	}

	// group id: just store the numeric id for now until Go supports looking up group names
	req.Header.Set("X-Amz-Meta-Gid", fmt.Sprintf("%d", info.Gid))

	// store the permissions as an octal number
	req.Header.Set("X-Amz-Meta-Mode", fmt.Sprintf("0%o", info.Mode))

	// store the modified date in a nice format
	sec := info.Mtime_ns / 1e9
	ns := info.Mtime_ns % 1e9
	date := time.SecondsToLocalTime(sec).String()
	if ns == 0 {
		req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d (%s)", sec, date))
	} else {
		req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d.%09d (%s)", sec, ns, date))
	}

	// set the content-type by looking up the MIME type
	mimetype := default_mime_type
	switch {
	case info.IsDirectory():
		mimetype = directory_mime_type
	case info.IsSymlink():
		mimetype = symlink_mime_type
	default:
		if dot := strings.LastIndex(info.Name, "."); dot >= 0 && dot+1 < len(info.Name) {
			extension := strings.ToLower(info.Name[dot:])
			if kind := mime.TypeByExtension(extension); kind != "" {
				mimetype = kind
			}
		}
	}
	req.Header.Set("Content-Type", mimetype)
}
开发者ID:russross,项目名称:propolis,代码行数:49,代码来源:s3.go

示例4: copyDirectory

func (self *Syncer) copyDirectory(srcName string, stat *os.FileInfo, dstName string, out chan SyncStats) {
	stats := new(SyncStats)
	defer func() { out <- *stats }()

	err := os.Mkdir(dstName, stat.Permission())
	if err != nil {
		stats.ErrorCount++
		return
	}
	stats.DirsCreated++
	if self.Verbose {
		fmt.Fprintln(self.VerboseWriter, dstName)
	}

	ops := new(outstandingOps)
	go self.SyncDirectories(srcName, dstName, ops.new())
	ops.wait(stats)
}
开发者ID:bradfitz,项目名称:gotsync,代码行数:18,代码来源:gotsync.go

示例5: canWrite

func canWrite(stat *os.FileInfo, euid, egid int) bool {
	perm := stat.Permission()
	return perm&02 != 0 || perm&020 != 0 && egid == stat.Gid || perm&0200 != 0 && euid == stat.Uid
}
开发者ID:ssrl,项目名称:gonrun,代码行数:4,代码来源:gonrun.go

示例6: main

/*
 Entry point. Used for setting some variables and parsing the command line.
*/
func main() {
	var err os.Error
	var rootPathDir *os.FileInfo

	// parse command line arguments
	flag.Parse()

	if *flagQuieterMode {
		logger.SetVerbosityLevel(logger.ERROR)
	} else if *flagQuietMode {
		logger.SetVerbosityLevel(logger.WARN)
	} else if *flagVerboseMode {
		logger.SetVerbosityLevel(logger.DEBUG)
	}

	if *flagClean {
		clean()
		os.Exit(0)
	}

	// get the compiler/linker executable
	switch os.Getenv("GOARCH") {
	case "amd64":
		compilerBin = "6g"
		linkerBin = "6l"
		objExt = ".6"
	case "386":
		compilerBin = "8g"
		linkerBin = "8l"
		objExt = ".8"
	case "arm":
		compilerBin = "5g"
		linkerBin = "5l"
		objExt = ".5"
	default:
		logger.Error("Please specify a valid GOARCH (amd64/386/arm).\n")
		os.Exit(1)
	}

	// get the complete path to the compiler/linker
	compilerBin, err = exec.LookPath(compilerBin)
	if err != nil {
		logger.Error("Could not find compiler %s: %s\n", compilerBin, err)
		os.Exit(127)
	}
	linkerBin, err = exec.LookPath(linkerBin)
	if err != nil {
		logger.Error("Could not find linker %s: %s\n", linkerBin, err)
		os.Exit(127)
	}
	gopackBin, err = exec.LookPath(gopackBin)
	if err != nil {
		logger.Error("Could not find gopack executable (%s): %s\n", gopackBin, err)
		os.Exit(127)
	}

	// get the root path from where the application was called
	// and its permissions (used for subdirectories)
	if rootPath, err = os.Getwd(); err != nil {
		logger.Error("Could not get the root path: %s\n", err)
		os.Exit(1)
	}
	if rootPathDir, err = os.Stat(rootPath); err != nil {
		logger.Error("Could not read the root path: %s\n", err)
		os.Exit(1)
	}
	rootPathPerm = rootPathDir.Permission()

	// create the package container
	goPackages = godata.NewGoPackageContainer()

	// check if -o with path
	if *flagOutputFileName != "" {
		dir, err := os.Stat(*flagOutputFileName)
		if err != nil {
			// doesn't exist? try to make it if it's a path
			if (*flagOutputFileName)[len(*flagOutputFileName)-1] == '/' {
				err = os.MkdirAll(*flagOutputFileName, rootPathPerm)
				if err == nil {
					outputDirPrefix = *flagOutputFileName
				}
			} else {
				godata.DefaultOutputFileName = *flagOutputFileName
			}
		} else if dir.IsDirectory() {
			if (*flagOutputFileName)[len(*flagOutputFileName)-1] == '/' {
				outputDirPrefix = *flagOutputFileName
			} else {
				outputDirPrefix = *flagOutputFileName + "/"
			}
		} else {
			godata.DefaultOutputFileName = *flagOutputFileName
		}

		// make path to output file
		if outputDirPrefix == "" && strings.Index(*flagOutputFileName, "/") != -1 {
			err = os.MkdirAll((*flagOutputFileName)[0:strings.LastIndex(*flagOutputFileName, "/")], rootPathPerm)
//.........这里部分代码省略.........
开发者ID:ShadowIce,项目名称:gobuild,代码行数:101,代码来源:gobuild.go

示例7: copyRegularFile

func (self *Syncer) copyRegularFile(srcName string, stat *os.FileInfo, dstName string, out chan SyncStats) {
	stats := new(SyncStats)
	defer func() { out <- *stats }()

	outfd, err := os.Open(dstName, os.O_CREATE|os.O_EXCL|os.O_WRONLY,
		stat.Permission())
	if err != nil {
		fmt.Fprintf(self.ErrorWriter,
			"Error opening copy output file %s: %s\n",
			dstName, err)
		stats.ErrorCount++
		return
	}
	defer outfd.Close()

	infd, err := os.Open(srcName, os.O_RDONLY, 0)
	if err != nil {
		fmt.Fprintf(self.ErrorWriter,
			"Error opening copy source file %s: %s\n",
			srcName, err)
		stats.ErrorCount++
		return
	}
	defer infd.Close()

	const BUF_SIZE = 1024 * 256
	buf := make([]byte, BUF_SIZE)
	bytesRemain := stat.Size
	for bytesRemain > 0 {
		n, err := infd.Read(buf)
		switch {
		case n == 0:
			break
		case n < 0:
			stats.ErrorCount++
			fmt.Fprintf(self.ErrorWriter, "Error copying file %s in read: %s",
				srcName, err)
			return
		default:
			outN, err := outfd.Write(buf[0:n])
			if err != nil || outN != n {
				fmt.Fprintf(self.ErrorWriter, "Error copying file %s in write: %s",
					srcName, err)
				return
			}
			bytesRemain -= int64(outN)
		}
	}

	// Close it explicitly before we syscall.Utime() it, even
	// though the precautionary defer'd Close() above will close
	// it again later.  That's harmless.
	err = outfd.Close()
	if err != nil {
		stats.ErrorCount++
		return
	}

	// When the Chtimes patch is merged upstream...
	// err = os.Chtimes(dstName, stat.Atime_ns, stat.Mtime_ns)
	var tv []syscall.Timeval = make([]syscall.Timeval, 2)
	tv[0] = syscall.NsecToTimeval(stat.Atime_ns)
	tv[1] = syscall.NsecToTimeval(stat.Mtime_ns)
	errno := syscall.Utimes(dstName, tv)
	if errno != 0 {
		fmt.Fprintf(self.ErrorWriter, "Error modifying utimes on %s: %v",
			dstName, errno)
		stats.ErrorCount++
		return
	}

	stats.FilesCreated++
	if self.Verbose {
		fmt.Fprintln(self.VerboseWriter, dstName)
	}
}
开发者ID:bradfitz,项目名称:gotsync,代码行数:76,代码来源:gotsync.go


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