Beispiel #1
0
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
	}

}
Beispiel #2
0
// 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{})
}
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())
	}
}
Beispiel #4
0
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
}
Beispiel #5
0
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

}
Beispiel #6
0
//
// 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

}
Beispiel #7
0
func init() {

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

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

	fi := InMemoryFileInfo{}
	ifi := os.FileInfo(&fi)
	_ = ifi

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

}
Beispiel #8
0
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

}
Beispiel #9
0
//
// 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
}
Beispiel #10
0
func TestNewFileInfoNilPointer(t *testing.T) {
	fi := NewFileInfo(os.FileInfo(nil))
	if fi != nil {
		t.Fatalf("should be nil")
	}
}
Beispiel #11
0
func (f *DsDir) Stat() (os.FileInfo, error) {
	return os.FileInfo(*f), nil
}