本文整理汇总了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
}
}
示例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{})
}
示例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())
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例9: TestNewFileInfoNilPointer
func TestNewFileInfoNilPointer(t *testing.T) {
fi := NewFileInfo(os.FileInfo(nil))
if fi != nil {
t.Fatalf("should be nil")
}
}
示例10: Stat
func (f *DsDir) Stat() (os.FileInfo, error) {
return os.FileInfo(*f), nil
}