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


Golang os.FileInfo函数代码示例

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


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

示例1: Readdir

func (f *InMemoryFile) Readdir(n int) (fis []os.FileInfo, err error) {

	fis = make([]os.FileInfo, 0, len(f.memDir))
	for _, f1 := range f.memDir {
		ff := f1.(*InMemoryFile)
		fis = append(fis, os.FileInfo(&InMemoryFileInfo{file: ff}))
	}
	f.fs.readdirsorter(fis)

	wantAll := n <= 0

	if wantAll {
		return fis, nil
	}

	// Actually we would need memDirFetchPos
	// holding the latest retrieved file in
	// a forwardly-linked-list mimic.
	// Compare https://golang.org/src/os/file_windows.go
	// Instead: We either or return *all* available files
	// or empty slice plus io.EOF
	if f.memDirFetchPos == 0 {
		f.memDirFetchPos = len(fis)
		return fis, nil
	} else {
		f.memDirFetchPos = 0
		return []os.FileInfo{}, io.EOF
	}

}
开发者ID:aarzilli,项目名称:tools,代码行数:30,代码来源:40_file_impl.go

示例2: TestTypes

// Some assertions around filehandle's applicability
func TestTypes(t *testing.T) {
	_ = os.FileInfo(&FileHandle{})
	_ = io.Closer(&FileHandle{})
	_ = io.Reader(&FileHandle{})
	_ = io.ReaderAt(&FileHandle{})
	_ = io.WriterTo(&FileHandle{})
	_ = io.Seeker(&FileHandle{})
}
开发者ID:zhgwenming,项目名称:cbfs,代码行数:9,代码来源:client_test.go

示例3: Error

func (t notADirectoryError) Error() string {
	fileInfo := os.FileInfo(t)
	switch {
	case fileInfo.Mode().IsRegular():
		return "file is a regular file"
	default:
		return fmt.Sprintf("file mode is: %s", fileInfo.Mode().String())
	}
}
开发者ID:COLDTURNIP,项目名称:kubernetes,代码行数:9,代码来源:be_a_directory.go

示例4: Stat

func (fs *dsFileSys) Stat(path string) (os.FileInfo, error) {

	f, err := fs.fileByPath(path)
	if err != nil && err != datastore.ErrNoSuchEntity && err != fsi.ErrRootDirNoFile {
		log.Fatalf("OTHER ERROR %v", err)

		return nil, err
	}
	if err == datastore.ErrNoSuchEntity || err == fsi.ErrRootDirNoFile {
		// log.Printf("isno file err %-24q =>  %v", path, err)
		dir, err := fs.dirByPath(path)
		if err != nil {
			return nil, err
		}
		fiDir := os.FileInfo(dir)
		// log.Printf("Stat for dire %-24q => %-24v, %v", path, fiDir.Name(), err)
		return fiDir, nil
	}

	fiFi := os.FileInfo(f)
	// log.Printf("Stat for file %-24q => %-24v, %v", path, fiFi.Name(), err)
	return fiFi, nil
}
开发者ID:aarzilli,项目名称:tools,代码行数:23,代码来源:30_fs_impl.go

示例5: init

func init() {

	// forcing our implementations
	// to comply with our interfaces

	f := DsFile{}
	ifa := fsi.File(&f)
	_ = ifa

	ifi := os.FileInfo(&f)
	_ = ifi

	fs := dsFileSys{}
	ifs := fsi.FileSystem(&fs)
	_ = ifs

}
开发者ID:aarzilli,项目名称:tools,代码行数:17,代码来源:0_init.go

示例6: dirsByPath

//
// dirsByPath might not find recently added directories.
// Upon finding nothing, it therefore returns the
// "warning" fsi.EmptyQueryResult
//
// It is currently used by ReadDir
func (fs *dsFileSys) dirsByPath(name string) ([]os.FileInfo, error) {

	dir, bname := fs.SplitX(name)

	var fis []os.FileInfo

	dirs, err := fs.SubtreeByPath(dir+bname, true)
	for _, v := range dirs {
		// log.Printf("%15v => %-24v", "", v.Dir+v.BName)
		fi := os.FileInfo(v)
		fis = append(fis, fi)
	}

	fs.dirsorter(fis)

	return fis, err

}
开发者ID:aarzilli,项目名称:tools,代码行数:24,代码来源:low_level_dirs.go

示例7: init

func init() {

	// forcing our implementations
	// to comply with our interfaces

	f := os.File{}
	ifa := fsi.File(&f)
	_ = ifa

	var fi os.FileInfo
	ifi := os.FileInfo(fi) // of course idiotic, but we keep the pattern
	_ = ifi

	fs := osFileSys{}
	ifs := fsi.FileSystem(&fs)
	_ = ifs

}
开发者ID:aarzilli,项目名称:tools,代码行数:18,代码来源:0-init.go

示例8: ReadDir

//
// ReadDir might not find recently added directories.
func (fs *dsFileSys) ReadDir(name string) ([]os.FileInfo, error) {

	dirs, err := fs.dirsByPath(name)
	// fs.Ctx().Infof("dsfs readdir %-20v dirs %v", name, len(dirs))
	if err != nil && err != fsi.EmptyQueryResult {
		return nil, err
	}
	fs.dirsorter(dirs)

	files, err := fs.filesByPath(name)
	// fs.Ctx().Infof("dsfs readdir %-20v fils %v %v", name, len(files), err)
	if err != nil {
		return nil, err
	}
	fs.filesorter(files)

	for _, v := range files {
		dirs = append(dirs, os.FileInfo(v))
	}
	return dirs, nil
}
开发者ID:aarzilli,项目名称:tools,代码行数:23,代码来源:30_fs_impl.go

示例9: TestNewFileInfoNilPointer

func TestNewFileInfoNilPointer(t *testing.T) {
	fi := NewFileInfo(os.FileInfo(nil))
	if fi != nil {
		t.Fatalf("should be nil")
	}
}
开发者ID:rnaveiras,项目名称:packer,代码行数:6,代码来源:fileinfo_test.go

示例10: Stat

func (f *DsDir) Stat() (os.FileInfo, error) {
	return os.FileInfo(*f), nil
}
开发者ID:aarzilli,项目名称:tools,代码行数:3,代码来源:42_dir_impl.go


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