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


Golang FileInfo.Sys方法代码示例

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


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

示例1: fileStatFromInfoOs

func fileStatFromInfoOs(fi os.FileInfo, flags *uint32, fileStat *FileStat) {
	if statt, ok := fi.Sys().(*syscall.Stat_t); ok {
		*flags |= ssh_FILEXFER_ATTR_UIDGID
		fileStat.UID = statt.Uid
		fileStat.GID = statt.Gid
	}
}
开发者ID:ZombieHippie,项目名称:drone-sftp-cache,代码行数:7,代码来源:attrs_unix.go

示例2: GetOwnerAndGroup

// We have a dummy version of this call in posix.go.
// Windows does not implement the syscall.Stat_t type we
// need, but the *nixes do. We use this in util.AddToArchive
// to set owner/group on files being added to a tar archive.
func GetOwnerAndGroup(finfo os.FileInfo, header *tar.Header) {
	systat := finfo.Sys().(*syscall.Stat_t)
	if systat != nil {
		header.Uid = int(systat.Uid)
		header.Gid = int(systat.Gid)
	}
}
开发者ID:APTrust,项目名称:exchange,代码行数:11,代码来源:posix.go

示例3: UidAndGidFlags

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

	// Mount, setting the flags. Make sure to set the directory mode such that we
	// can actually see the contents.
	args := []string{
		"--uid", "1719",
		"--gid", "2329",
		"--dir-mode", "555",
		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(1719, fi.Sys().(*syscall.Stat_t).Uid)
	ExpectEq(2329, fi.Sys().(*syscall.Stat_t).Gid)

	fi, err = os.Lstat(path.Join(t.dir, canned.TopLevelDir))
	AssertEq(nil, err)
	ExpectEq(1719, fi.Sys().(*syscall.Stat_t).Uid)
	ExpectEq(2329, fi.Sys().(*syscall.Stat_t).Gid)
}
开发者ID:zfo,项目名称:gcsfuse,代码行数:29,代码来源:gcsfuse_test.go

示例4: getInfo

func (f *File) getInfo(path string) error {
	var fstat os.FileInfo
	var err error
	f.Path = path
	fstat, err = os.Stat(path)
	if err != nil {
		fstat, err = os.Lstat(path)
		if err != nil {
			return err
		}
	}
	f.FileInfo = fstat
	f.Relpath = path[len(rootdir):]
	// 	f.Relpath, err = filepath.Rel(rootdir, f.Path)
	// 	if err != nil {
	// 		log.Fatalln(err.Error())
	// 		return
	// 	}
	f.Stat = fstat.Sys().(*syscall.Stat_t)
	f.getExt()

	if !f.IsDir() && !f.IsLink() {
		f.IsFile = true
	}
	return nil
}
开发者ID:kiyor,项目名称:gfind,代码行数:26,代码来源:find.go

示例5: fillExtra

func (node *Node) fillExtra(path string, fi os.FileInfo) error {
	stat, ok := toStatT(fi.Sys())
	if !ok {
		return nil
	}

	node.Inode = uint64(stat.ino())

	node.fillTimes(stat)

	var err error

	if err = node.fillUser(stat); err != nil {
		return errors.Annotate(err, "fillExtra")
	}

	switch node.Type {
	case "file":
		node.Size = uint64(stat.size())
		node.Links = uint64(stat.nlink())
	case "dir":
	case "symlink":
		node.LinkTarget, err = os.Readlink(path)
	case "dev":
		node.Device = uint64(stat.rdev())
	case "chardev":
		node.Device = uint64(stat.rdev())
	case "fifo":
	case "socket":
	default:
		err = fmt.Errorf("invalid node type %q", node.Type)
	}

	return err
}
开发者ID:fawick,项目名称:restic,代码行数:35,代码来源:node.go

示例6: fetchFileDetailsJSON

func fetchFileDetailsJSON(m *FileDetailsJSON, fi os.FileInfo) {
	if !*excludeSize {
		m.Size = fi.Size()
	}
	if !*excludeMtime {
		tmp := fi.ModTime()
		m.Mtime = tmp.Format(*timeFormat)
	}
	stat := fi.Sys().(*syscall.Stat_t)
	if !*excludeUid {
		m.Uid = stat.Uid
	}
	if !*excludeGid {
		m.Gid = stat.Gid
	}
	if !*excludeInode {
		m.Inode = stat.Ino
	}
	if !*excludeAtime {
		tmp := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
		m.Atime = tmp.Format(*timeFormat)
	}
	if !*excludeCtime {
		tmp := time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec))
		m.Ctime = tmp.Format(*timeFormat)
	}
	/*
	   if 1==0 {
	       log.Print("Number of links: ",stat.Nlink)
	   }
	*/
}
开发者ID:humbytheory,项目名称:filewalker,代码行数:32,代码来源:main.go

示例7: New

func New(fi os.FileInfo) *ExtraStat {
	return &ExtraStat{
		AccessTime:  time.Unix(int64(fi.Sys().(*syscall.Dir).Atime), 0),
		ModTime:     fi.ModTime(),
		CreatedTime: fi.ModTime(),
	}
}
开发者ID:hnakamur,项目名称:extstat,代码行数:7,代码来源:extstat_plan9.go

示例8: fi2fo

func fi2fo(fi os.FileInfo, p string) FileObj {
	st, ok := fi.Sys().(*syscall.Stat_t)
	if !ok {
		panic(fmt.Sprintf("fen: type should be *syscall.Stat_t, %T instead", st))
	}
	return FileObj{Name: p, Atim: st.Atim, Mtim: st.Mtim, Ctim: st.Ctim}
}
开发者ID:Raskal8,项目名称:go-ethereum,代码行数:7,代码来源:watcher_fen.go

示例9: Next

// Returns an open reader for the next file, along with a FileSummary.
// Returns io.EOF when it reaches the last file.
// The caller is responsible for closing the reader.
func (iter *FileSystemIterator) Next() (io.ReadCloser, *FileSummary, error) {
	iter.index += 1
	if iter.index >= len(iter.files) {
		return nil, nil, io.EOF
	}
	filePath := iter.files[iter.index]
	var stat os.FileInfo
	var err error
	if stat, err = os.Stat(filePath); os.IsNotExist(err) {
		return nil, nil, fmt.Errorf("File '%s' does not exist.", filePath)
	}
	fileMode := stat.Mode()
	fs := &FileSummary{
		RelPath:       strings.Replace(filePath, iter.rootPath+string(os.PathSeparator), "", 1),
		AbsPath:       filePath,
		Mode:          fileMode,
		Size:          stat.Size(),
		ModTime:       stat.ModTime(),
		IsDir:         stat.IsDir(),
		IsRegularFile: fileMode.IsRegular(),
	}
	systat := stat.Sys().(*syscall.Stat_t)
	if systat != nil {
		fs.Uid = int(systat.Uid)
		fs.Gid = int(systat.Gid)
	}
	file, err := os.Open(filePath)
	if err != nil {
		return nil, fs, fmt.Errorf("Cannot read file '%s': %v", filePath, err)
	}
	return file, fs, nil
}
开发者ID:APTrust,项目名称:exchange,代码行数:35,代码来源:filesystem_iterator.go

示例10: getFileOwner

func getFileOwner(info os.FileInfo) (uid, gid string) {

	uid = fmt.Sprint(info.Sys().(*syscall.Stat_t).Uid)
	gid = fmt.Sprint(info.Sys().(*syscall.Stat_t).Gid)

	return uid, gid
}
开发者ID:diogomonica,项目名称:actuary,代码行数:7,代码来源:checks.go

示例11: getFileUserAndGroupId

// getFileUserAndGroupId returns owner user and group ids from given FileInfo.
func getFileUserAndGroupId(fi os.FileInfo) (uid uint, gid uint, err error) { // {{{
	if st, ok := fi.Sys().(*syscall.Stat_t); ok {
		return uint(st.Uid), uint(st.Gid), nil
	}
	err = errors.New("Stat failed on: " + fi.Name())
	return
} // }}}
开发者ID:wor,项目名称:goanysync,代码行数:8,代码来源:goanysync.go

示例12: File

func (m *MetadataEncoder) File(path string, fi os.FileInfo, mime string,
	digest *[sha256.Size]byte) error {

	_, err := m.e.Encode(TypeFile)
	if err != nil {
		return err
	}

	if digest == nil {
		digest = &[sha256.Size]byte{}
	}
	stat, ok := fi.Sys().(*syscall.Stat_t)
	if !ok {
		stat = &syscall.Stat_t{
			Uid: 0xffffffff,
			Gid: 0xffffffff,
		}
	}
	_, err = m.e.Encode(File{
		Name:     path,
		Mode:     fi.Mode(),
		Owner:    int(stat.Uid),
		Group:    int(stat.Gid),
		Size:     fi.Size(),
		Modified: fi.ModTime(),

		MimeType: mime,
		Digest:   *digest,
	})
	if err != nil {
		return err
	}

	return nil
}
开发者ID:jcvernaleo,项目名称:acdb,代码行数:35,代码来源:metadata.go

示例13: Dir

func (m *MetadataEncoder) Dir(path string, fi os.FileInfo) error {
	_, err := m.e.Encode(TypeDir)
	if err != nil {
		return err
	}

	stat, ok := fi.Sys().(*syscall.Stat_t)
	if !ok {
		stat = &syscall.Stat_t{
			Uid: 0xffffffff,
			Gid: 0xffffffff,
		}
	}
	_, err = m.e.Encode(Dir{
		Name:     path,
		Mode:     fi.Mode(),
		Owner:    int(stat.Uid),
		Group:    int(stat.Gid),
		Modified: fi.ModTime(),
	})
	if err != nil {
		return err
	}

	return nil
}
开发者ID:jcvernaleo,项目名称:acdb,代码行数:26,代码来源:metadata.go

示例14: addFile

func (v *containerVolume) addFile(path string, info os.FileInfo, err error) error {
	if err != nil {
		return err
	}

	relPath := path[len(filepath.Dir(v.hostPath))+1:] // relative to volume parent directory (<docker>/vfs/dir/)
	th, err := tar.FileInfoHeader(info, relPath)
	if err != nil {
		return err
	}
	th.Name = relPath
	if si, ok := info.Sys().(*syscall.Stat_t); ok {
		th.Uid = int(si.Uid)
		th.Gid = int(si.Gid)
	}

	if err := v.tw.WriteHeader(th); err != nil {
		return err
	}

	if !info.Mode().IsDir() {
		file, err := os.Open(path)
		if err != nil {
			return err
		}
		n, err := io.Copy(v.tw, file)
		if err != nil {
			return err
		}
		v.size = v.size + uint(n)
	}
	return nil
}
开发者ID:calmh,项目名称:docker-backup,代码行数:33,代码来源:volumes.go

示例15: getTimespec

func getTimespec(fi os.FileInfo) (t timespec) {
	stat := fi.Sys().(*syscall.Win32FileAttributeData)
	t.atime.v = time.Unix(0, stat.LastAccessTime.Nanoseconds())
	t.mtime.v = time.Unix(0, stat.LastWriteTime.Nanoseconds())
	t.btime.v = time.Unix(0, stat.CreationTime.Nanoseconds())
	return t
}
开发者ID:postfix,项目名称:times,代码行数:7,代码来源:times_windows.go


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