Example #1
0
// complies  with   os.Open()
// conflicts with  vfs.Open() signature
// conflicts with file.Open() interface of Afero
func (fs *dsFileSys) Open(name string) (fsi.File, error) {

	// explicitly requesting directory?
	_, bname := fs.SplitX(name)
	if strings.HasSuffix(bname, "/") {
		dir, err := fs.dirByPath(name)
		if err == nil {
			ff := fsi.File(&dir)
			return ff, nil
		}
	}

	// otherwise: try file, then directory
	f, err := fs.fileByPath(name)

	if err != nil && err != datastore.ErrNoSuchEntity && err != fsi.ErrRootDirNoFile {
		return nil, err
	}
	if err == datastore.ErrNoSuchEntity || err == fsi.ErrRootDirNoFile {
		// http.FileServer requires, that
		// we return a directory here.
		// It's also compliant to os.Open(),
		// where "os.File" means directories too.
		dir, err2 := fs.dirByPath(name)
		if err2 != nil {
			return nil, err
		}
		ff := fsi.File(&dir)
		return ff, nil
	}

	atomic.StoreInt64(&f.at, 0) // why is this not nested into f.Lock()-f.Unlock()?

	if f.closed == false { // already open
		// return ErrFileInUse // instead of waiting for lock?
	}

	f.Lock()
	f.closed = false
	f.Unlock()

	// return &f, nil
	ff := fsi.File(&f)
	return ff, nil
}
Example #2
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

}
Example #3
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

}
Example #4
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

}
Example #5
0
// Create opens for read-write.
// Open opens for readonly access.
func (fs *dsFileSys) Create(name string) (fsi.File, error) {

	// WriteFile & Create
	dir, bname := fs.SplitX(name)

	f := DsFile{}
	f.fSys = fs
	f.BName = common.Filify(bname)
	f.Dir = dir
	f.MModTime = time.Now()
	f.MMode = 0644

	// let all the properties by set by fs.saveFileByPath
	err := f.Sync()
	if err != nil {
		return nil, err
	}

	// return &f, nil
	ff := fsi.File(&f)
	return ff, err

}