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


Golang FileInfo.Mode方法代码示例

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


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

示例1: GetHash

// Return the hash for path stored in the xattrs. If the hash is out of date,
// the hash is computed anew, unless `compute` is false in which case nil is
// returned.
func GetHash(path string, info os.FileInfo, compute bool) (mh.Multihash, error) {
	if info.Mode()&os.ModeSymlink != 0 {
		return symlinkHash(path)
	}

	hashTimeStr, err := attrs.Get(path, XattrHashTime)
	if err != nil {
		if compute {
			return HashFile(path, info)
		} else if IsNoData(err) {
			// ignore error
			return nil, nil
		} else {
			return nil, err
		}
	}

	hashTime, err := time.Parse(time.RFC3339Nano, string(hashTimeStr))
	if err != nil {
		return nil, err
	}

	if hashTime != info.ModTime() {
		if compute {
			return HashFile(path, info)
		} else {
			return nil, nil
		}
	}

	return attrs.Get(path, XattrHash)
}
开发者ID:mildred,项目名称:doc,代码行数:35,代码来源:hash.go

示例2: shouldRead

func (f *Filesystem) shouldRead(filePath string, fi os.FileInfo) (bool, error) {
	if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
		link, err := filepath.EvalSymlinks(filePath)
		if err != nil {
			jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", filePath, err)
			return false, nil
		}
		linkfi, err := os.Stat(link)
		if err != nil {
			jww.ERROR.Printf("Cannot stat '%s', error was: %s", link, err)
			return false, nil
		}
		if !linkfi.Mode().IsRegular() {
			jww.ERROR.Printf("Symbolic links for directories not supported, skipping '%s'", filePath)
		}
		return false, nil
	}

	if fi.IsDir() {
		if f.avoid(filePath) || isNonProcessablePath(filePath) {
			return false, filepath.SkipDir
		}
		return false, nil
	}

	if isNonProcessablePath(filePath) {
		return false, nil
	}
	return true, nil
}
开发者ID:yanwushuang,项目名称:pango,代码行数:30,代码来源:filesystem.go

示例3: checkFile

func checkFile(f os.FileInfo) bool {
	if f.Mode().IsRegular() {
		return true
	}

	return false
}
开发者ID:dbulkow,项目名称:ansible_webui,代码行数:7,代码来源:ansible.go

示例4: compress

func (wft *tarWalk) compress(name, fpath string, fi os.FileInfo) (bool, error) {
	isSym := fi.Mode()&os.ModeSymlink > 0
	link := ""
	if isSym {
		link, _ = os.Readlink(fpath)
	}

	hdr, err := tar.FileInfoHeader(fi, link)
	if err != nil {
		return false, err
	}
	hdr.Name = name

	tw := wft.tw
	err = tw.WriteHeader(hdr)
	if err != nil {
		return false, err
	}

	if isSym == false {
		fr, err := os.Open(fpath)
		if err != nil {
			return false, err
		}
		defer fr.Close()
		_, err = io.Copy(tw, fr)
		if err != nil {
			return false, err
		}
		tw.Flush()
	}

	return true, nil
}
开发者ID:Linvas,项目名称:ant,代码行数:34,代码来源:pack.go

示例5: walkLeaf

func (wft *walkFileTree) walkLeaf(fpath string, fi os.FileInfo, err error) error {
	if err != nil {
		return err
	}

	if fpath == outputP {
		return nil
	}

	if fi.IsDir() {
		return nil
	}

	if ssym && fi.Mode()&os.ModeSymlink > 0 {
		return nil
	}

	name := wft.virPath(fpath)

	if wft.allfiles[name] {
		return nil
	}

	if added, err := wft.wak.compress(name, fpath, fi); added {
		if verbose {
			fmt.Printf("Compressed: %s\n", name)
		}
		wft.allfiles[name] = true
		return err
	} else {
		return err
	}
}
开发者ID:Linvas,项目名称:ant,代码行数:33,代码来源:pack.go

示例6: visit

func (self *Visitor) visit(path string, f os.FileInfo, err error) error {
	if f == nil {
		return err
	}
	if f.IsDir() {
		return nil
	} else if (f.Mode() & os.ModeSymlink) > 0 {
		return nil
	} else {
		if strings.HasSuffix(f.Name(), ".md") {
			fmt.Println(f)
			file, err := os.Open(f.Name())
			if err != nil {
				return err
			}
			input, _ := ioutil.ReadAll(file)
			input = regexp.MustCompile("\\[(.*?)\\]\\(<?(.*?)\\.md>?\\)").ReplaceAll(input, []byte("[$1](<$2.html>)"))
			var out *os.File
			if out, err = os.Create(strings.Replace(f.Name(), ".md", ".html", -1)); err != nil {
				fmt.Fprintf(os.Stderr, "Error creating %s: %v", f.Name(), err)
				os.Exit(-1)
			}
			defer out.Close()
			md := md2min.New("none")
			err = md.Parse(input, out)
			if err != nil {
				fmt.Fprintln(os.Stderr, "Parsing Error", err)
				os.Exit(-1)
			}
		}
	}
	return nil
}
开发者ID:spring0832,项目名称:golang-demo,代码行数:33,代码来源:build.go

示例7: checkWalk

// checkWalk is a helper function to sanity check for *.wsp files in a
// file tree walk.  If the file is valid, normal *.wsp nil is returned.
// Otherwise a non-nil error value is returned.
func checkWalk(path string, info os.FileInfo, err error) (bool, error) {
	// Did the Walk function hit an error on this file?
	if err != nil {
		log.Printf("%s\n", err)
		// File perm or exists error, log and skip
		return false, nil
	}

	// Sanity check our file
	if info.IsDir() {
		// Ignore dot-files and dot-directories
		if strings.HasPrefix(info.Name(), ".") {
			return false, filepath.SkipDir
		}
		return false, nil
	}
	if !info.Mode().IsRegular() {
		// Not a regular file
		return false, nil
	}
	if !strings.HasSuffix(path, ".wsp") {
		// Not a Whisper Database
		return false, nil
	}

	return true, nil
}
开发者ID:olivierHa,项目名称:buckytools,代码行数:30,代码来源:metrics.go

示例8: GetFile

func (ftp *FtpConnection) GetFile(local_path, remote_path string) error {
	var err error

	buf := new(bytes.Buffer)
	if err := ftp.Conn.Retrieve(remote_path, buf); err != nil {
		return err
	}

	var stat os.FileInfo
	stat, err = ftp.Stat(remote_path)
	if err != nil {
		return err
	}

	var file *os.File

	if file, err = os.OpenFile(local_path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, stat.Mode()); err != nil {
		return err
	}
	defer file.Close()

	file.Write(buf.Bytes())

	return nil
}
开发者ID:r3nic1e,项目名称:bbdownloader,代码行数:25,代码来源:ftp.go

示例9: writeTarHeader

// writeTarHeader writes tar header for given file, returns error if operation fails
func (t *stiTar) writeTarHeader(tarWriter *tar.Writer, dir string, path string, info os.FileInfo, includeDirInPath bool) error {
	var (
		link string
		err  error
	)
	if info.Mode()&os.ModeSymlink != 0 {
		link, err = os.Readlink(path)
		if err != nil {
			return err
		}
	}
	header, err := tar.FileInfoHeader(info, link)
	if err != nil {
		return err
	}
	prefix := dir
	if includeDirInPath {
		prefix = filepath.Dir(prefix)
	}
	header.Name = filepath.ToSlash(path[1+len(prefix):])
	glog.V(5).Infof("Adding to tar: %s as %s", path, header.Name)
	if err = tarWriter.WriteHeader(header); err != nil {
		return err
	}

	return nil
}
开发者ID:kcbabo,项目名称:origin,代码行数:28,代码来源:tar.go

示例10: parseAndStore

// Append the paths to an array in case that they are markdown files.
func (site *Site) parseAndStore(path string, fileInfo os.FileInfo, inputErr error) (err error) {
	if inputErr != nil {
		return inputErr
	}

	slugsPresence := make(map[string]bool)

	if !fileInfo.Mode().IsDir() && strings.HasSuffix(path, ".md") {
		file, err := file.New(path)
		if err != nil {
			return err
		}

		if _, present := slugsPresence[file.Slug]; present {
			return newUniqueSlugError(file.Slug)
		}
		slugsPresence[file.Slug] = true

		// Add the pages or articles to the proper array on the site
		if file.IsPage {
			site.Pages = append(site.Pages, file)
		} else {
			site.Articles = append(site.Articles, file)

			// Just supported on Articles
			if len(file.Tags) > 0 {
				site.AppendUniqueTags(file.Tags)
			}
			site.AppendUniqueCategory(file.Category)
		}
	}
	return
}
开发者ID:repos-blogs-static,项目名称:polo,代码行数:34,代码来源:types.go

示例11: Print

// Prints the filesystem to stdout, useful for testing.
// Not part of the filesystem interface.
func (mf *MockFilesystem) Print() {
	var (
		dirs   []string
		lines  [][]interface{}
		path   string
		f      File
		fi     os.FileInfo
		files  []os.FileInfo
		maxlen int
	)
	dirs = append(dirs, "/")
	maxlen = 1
	for len(dirs) > 0 {
		path = dirs[0]
		dirs = dirs[1:]
		f, _ = mf.Open(path)
		fi, _ = f.Stat()
		files, _ = f.Readdir(100)
		for _, fi = range files {
			name := filepath.Join(path, fi.Name())
			line := []interface{}{name, fi.Mode(), fi.IsDir()}
			lines = append(lines, line)
			if len(name) > maxlen {
				maxlen = len(name)
			}
			if fi.IsDir() {
				dirs = append(dirs, name)
			}
		}
	}
	fmtstr := fmt.Sprintf("%%-%vv %%v %%v\n", maxlen)
	for _, line := range lines {
		fmt.Printf(fmtstr, line[0], line[1], line[2])
	}
}
开发者ID:kurrik,项目名称:fauxfile,代码行数:37,代码来源:mockfilesystem.go

示例12: walkDir

func (w *walker) walkDir(relPath string, info os.FileInfo, dchan chan protocol.FileInfo) error {
	// A directory is "unchanged", if it
	//  - exists
	//  - has the same permissions as previously, unless we are ignoring permissions
	//  - was not marked deleted (since it apparently exists now)
	//  - was a directory previously (not a file or something else)
	//  - was not a symlink (since it's a directory now)
	//  - was not invalid (since it looks valid now)
	cf, ok := w.CurrentFiler.CurrentFile(relPath)
	permUnchanged := w.IgnorePerms || !cf.HasPermissionBits() || PermsEqual(cf.Permissions, uint32(info.Mode()))
	if ok && permUnchanged && !cf.IsDeleted() && cf.IsDirectory() && !cf.IsSymlink() && !cf.IsInvalid() {
		return nil
	}

	f := protocol.FileInfo{
		Name:          relPath,
		Type:          protocol.FileInfoTypeDirectory,
		Version:       cf.Version.Update(w.ShortID),
		Permissions:   uint32(info.Mode() & maskModePerm),
		NoPermissions: w.IgnorePerms,
		ModifiedS:     info.ModTime().Unix(),
		ModifiedNs:    int32(info.ModTime().Nanosecond()),
		ModifiedBy:    w.ShortID,
	}
	l.Debugln("dir:", relPath, f)

	select {
	case dchan <- f:
	case <-w.Cancel:
		return errors.New("cancelled")
	}

	return nil
}
开发者ID:nrm21,项目名称:syncthing,代码行数:34,代码来源:walk.go

示例13: FileAndDirModeFlags

func (t *GcsfuseTest) FileAndDirModeFlags() {
	var err error
	var fi os.FileInfo

	// Mount with non-standard modes.
	args := []string{
		"--file-mode", "461",
		"--dir-mode", "511",
		canned.FakeBucketName,
		t.dir,
	}

	err = t.runGcsfuse(args)
	AssertEq(nil, err)
	defer unmount(t.dir)

	// Stat contents.
	fi, err = os.Lstat(path.Join(t.dir, canned.TopLevelFile))
	AssertEq(nil, err)
	ExpectEq(os.FileMode(0461), fi.Mode())

	fi, err = os.Lstat(path.Join(t.dir, canned.TopLevelDir))
	AssertEq(nil, err)
	ExpectEq(0511|os.ModeDir, fi.Mode())
}
开发者ID:zfo,项目名称:gcsfuse,代码行数:25,代码来源:gcsfuse_test.go

示例14: CannedContents

func (t *GcsfuseTest) CannedContents() {
	var err error
	var fi os.FileInfo

	// Mount.
	args := []string{canned.FakeBucketName, t.dir}

	err = t.runGcsfuse(args)
	AssertEq(nil, err)
	defer unmount(t.dir)

	// Check the expected contents of the file system.
	fi, err = os.Lstat(path.Join(t.dir, canned.TopLevelFile))
	AssertEq(nil, err)
	ExpectEq(os.FileMode(0644), fi.Mode())

	contents, err := ioutil.ReadFile(path.Join(t.dir, canned.TopLevelFile))
	AssertEq(nil, err)
	ExpectEq(canned.TopLevelFile_Contents, string(contents))

	fi, err = os.Lstat(path.Join(t.dir, canned.TopLevelDir))
	AssertEq(nil, err)
	ExpectEq(0755|os.ModeDir, fi.Mode())

	// The implicit directory shouldn't be visible, since we don't have implicit
	// directories enabled.
	_, err = os.Lstat(path.Join(t.dir, path.Dir(canned.ImplicitDirFile)))
	ExpectTrue(os.IsNotExist(err), "err: %v", err)
}
开发者ID:zfo,项目名称:gcsfuse,代码行数:29,代码来源:gcsfuse_test.go

示例15: list

func list(path string, info os.FileInfo, node *fsNode, n *int) error {
	if (!info.IsDir() && !info.Mode().IsRegular()) || strings.HasPrefix(info.Name(), ".") {
		return errors.New("Non-regular file")
	}
	(*n)++
	if (*n) > fileNumberLimit {
		return errors.New("Over file limit") //limit number of files walked
	}
	node.Name = info.Name()
	node.Size = info.Size()
	node.Modified = info.ModTime()
	if !info.IsDir() {
		return nil
	}
	children, err := ioutil.ReadDir(path)
	if err != nil {
		return fmt.Errorf("Failed to list files")
	}
	node.Size = 0
	for _, i := range children {
		c := &fsNode{}
		p := filepath.Join(path, i.Name())
		if err := list(p, i, c, n); err != nil {
			continue
		}
		node.Size += c.Size
		node.Children = append(node.Children, c)
	}
	return nil
}
开发者ID:Zarloc,项目名称:cloud-torrent,代码行数:30,代码来源:server_files.go


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