// Open returns the file content in a dedicated bucket
351943
func (s *S3Storage) Open(filepath string) (File, error) {
	bucket, err := s.Bucket()

	if err != nil {
		return nil, err
	}

	key, err := s.Key(filepath)

	if err != nil {
		return nil, err
	}

	body, err := bucket.GetReader(s.Path(filepath))

	if err != nil {
		return nil, err
	}

	return &S3StorageFile{
		body,
		key,
		s,
	}, nil
}
1054626
func (b *Box) Open(name string) (http.File, error) {
	plog.Debug(b, "Open", "name", name)
	f, err := b.Resolve(name)
	if err != nil {
		if len(filepath.Ext(name)) == 0 {
			return b.openWoExt(name)
		}
		return f, err
	}
	f, err = file.NewFileR(name, f)
	plog.Debug(b, "Open", "name", f.Name(), "file", f.Name())
	return f, err
}
876420
func (a *AtomicFS) Open(ctx context.Context, path string) (ctxvfs.ReadSeekCloser, error) {
	fs := a.v.Load().(ctxvfs.NameSpace)
	return fs.Open(ctx, path)
}
618939
func (res *Resource) Open() {
	res.stmu.Lock()
	defer res.stmu.Unlock()

	res.chmu.Lock()
	res.ch = make(chan struct{})
	res.chmu.Unlock()
}
900043
func Open(paths ...string) gkv.KV {
	var path string
	if len(paths) != 0 {
		path = paths[0]
	} else {
		path = filepath.Join(gkv.ProjectDir(), "data")
	}
	f, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			err = os.MkdirAll(path, 0755)
		}
		if err != nil {
			panic(err)
		}
	} else if !f.IsDir() {
		path = filepath.Dir(path)
	}

	db := diskv.New(diskv.Options{
		BasePath:     path,
		Transform:    func(s string) []string { return []string{} },
		CacheSizeMax: 1024 * 1024,
	})
	return &KV{
		db: db,
	}
}
1332781
func (l *LogFS) Open(ctx context.Context, path string) (*File, error) {
	l.logger.Printf("%v: open: %v", l.name, path)
	f, err := l.fs.Open(ctx, path)
	if err != nil {
		l.logger.Printf("%v: open error: %v: %v", l.name, path, err)
	}
	return f, err
}
664334
func (s ErrCountFS) Open(ctx context.Context, path string) (*File, error) {
	f, err := s.fs.Open(ctx, path)
	if err == s.err {
		s.status.Add("open.count", 1)
	}
	s.status.Add("open.total", 1)
	return f, err
}
709759
func (hfs hashFS) Open(ctx context.Context, path string) (*File, error) {
	v, err := hfs.gs.Get(path)
	if err != nil {
		return nil, err
	}
	return hfs.fs.Open(ctx, v)
}
290411
func (f *IndexFile) Open() (err error) {
	defer func() {
		if err := recover(); err != nil {
			err = fmt.Errorf("[Index file: %s] %v", f.path, err)
			panic(err)
		}
	}()

	// Try to acquire a reference to the series file.
	f.sfileref, err = f.sfile.Acquire()
	if err != nil {
		return err
	}

	// Extract identifier from path name.
	f.id, f.level = ParseFilename(f.Path())

	data, err := mmap.Map(f.Path(), 0)
	if err != nil {
		f.sfileref.Release()
		return err
	}

	if err := f.UnmarshalBinary(data); err != nil {
		f.sfileref.Release()
		f.Close()
		return err
	}

	// The resource is now open
	f.res.Open()

	return nil
}
706228
func (m *mem) Open(_ context.Context, path string) (*File, error) {
	m.RLock()
	f, ok := m.data[path]
	m.RUnlock()

	if ok {
		return &File{
			ReadCloser: f.readCloser(),
			Name:       f.name,
			ModTime:    f.modTime,
			Size:       f.size(),
		}, nil
	}
	return nil, &notExistError{
		Path: path,
	}
}
365497
func (o *object) Open(accesslevel cloudstorage.AccessLevel) (*os.File, error) {

	if o.opened {
		return nil, fmt.Errorf("the store object is already opened. %s", o.cachepath)
	}

	readonly := accesslevel == cloudstorage.ReadOnly
	//gou.Infof("sftp object.Open(%q) readonly?%v", o.name, readonly)

	err := cloudstorage.EnsureDir(o.cachepath)
	if err != nil {
		return nil, fmt.Errorf("could not create cachedcopy's dir. cachepath=%q err=%v", o.cachepath, err)
	}

	cachedcopy, err := os.OpenFile(o.cachepath, os.O_RDWR|os.O_CREATE, 0665)
	if err != nil {
		return nil, fmt.Errorf("could not open cachedcopy file. cachepath=%q err=%v", o.cachepath, err)
	}
	//statinfo("About to do AFTER open() os.Create()", o.cachepath)

	// if readonly {
	// 	cachedcopy.Close()
	// 	cachedcopy, err = os.Open(o.cachepath)
	// 	gou.Debugf("just opened readonly?  %q?", o.cachepath)
	// 	if err != nil {
	// 		return nil, fmt.Errorf("sftp: error occurred opening file. storepath=%s tfile=%v err=%v",o.cachepath, cachedcopy.Name(), err)
	// 	}
	// }

	if o.file != nil {
		//gou.Debugf("has file so copy to local cached copy")
		_, err = io.Copy(cachedcopy, o.file)
		if err != nil {
			return nil, err
		}
	} else if o.fi == nil {
		// this is a new file
		//gou.Debugf("new file %s", o.name)
		//statinfo("new file statinfo", o.cachepath)
	} else if o.fi != nil {
		// existing file
		get := Concat(o.client.bucket, o.name)
		//gou.Debugf("existingfile, open %s", get)
		f, err := o.client.client.Open(get)
		if err != nil {
			gou.WarnCtx(o.client.clientCtx, "Could not get %q err=%v", get, err)
			return nil, err
		}
		o.file = f

		_, err = io.Copy(cachedcopy, f)
		if err != nil {
			gou.WarnCtx(o.client.clientCtx, "Could not copy %q err=%v", o.name, err)
			return nil, err
		}
		cachedcopy.Close()
		//statinfo("after close/iotutil readall", o.cachepath)

		cachedcopy, err = os.OpenFile(o.cachepath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0665)
		if err != nil {
			gou.Error(err)
			return nil, err
		}
	}

	o.cachedcopy = cachedcopy
	o.readonly = readonly
	o.opened = true

	// o.cachedcopy.Sync()
	// o.cachedcopy.Close()
	//gou.Debugf("opened %q  readonly?%v opened?%v", o.cachepath, o.readonly, o.opened)
	//gou.Infof("Open() returning cache copy %p", o.cachedcopy)
	return o.cachedcopy, nil

	//return nil, fmt.Errorf("fetch error retry cnt reached: obj=%s tfile=%v", o.name, o.cachepath)
}
277050
func (l *OSFileSystemLoader) Open(name string) (io.ReadCloser, error) {
	return os.Open(name)
}
1113975
func Open(getURL GetURLFunc, needsRenewal NeedsRenewalFunc, settings *Settings) (*File, error) {
	client := settings.Client
	if client == nil {
		client = http.DefaultClient
	}

	retryCtx := retrycontext.NewDefault()
	if settings.RetrySettings != nil {
		retryCtx.Settings = *settings.RetrySettings
	}

	f := &File{
		getURL:        getURL,
		retrySettings: &retryCtx.Settings,
		needsRenewal:  needsRenewal,
		client:        client,
		name:          "<remote file>",

		conns: make(map[string]*conn),
		stats: &hstats{},

		ConnStaleThreshold: defaultConnStaleThreshold,
		LogLevel:           defaultLogLevel,
		ForbidBacktracking: forbidBacktracking,
		DumpStats:          dumpStats,
		// number obtained through gut feeling
		// may not be suitable to all workloads
		MaxConns: 8,
	}
	f.Log = settings.Log

	if settings.LogLevel != 0 {
		f.LogLevel = settings.LogLevel
	}
	if settings.ForbidBacktracking {
		f.ForbidBacktracking = true
	}
	if settings.DumpStats {
		f.DumpStats = true
	}

	urlStr, err := getURL()
	if err != nil {
		return nil, errors.WithMessage(normalizeError(err), "htfs.Open (getting URL)")
	}
	f.currentURL = urlStr

	c, err := f.borrowConn(0)
	if err != nil {
		return nil, errors.WithMessage(normalizeError(err), "htfs.Open (initial request)")
	}
	f.header = c.header

	err = f.returnConn(c)
	if err != nil {
		return nil, errors.WithMessage(normalizeError(err), "htfs.Open (return conn after initial request)")
	}

	f.requestURL = c.requestURL

	if c.statusCode == 206 {
		rangeHeader := c.header.Get("content-range")
		rangeTokens := strings.Split(rangeHeader, "/")
		totalBytesStr := rangeTokens[len(rangeTokens)-1]
		f.size, err = strconv.ParseInt(totalBytesStr, 10, 64)
		if err != nil {
			return nil, fmt.Errorf("Could not parse file size: %s", err.Error())
		}
	} else if c.statusCode == 200 {
		f.size = c.contentLength
	}

	// we have to use requestURL because we want the URL after
	// redirect (for hosts like sourceforge)
	pathTokens := strings.Split(f.requestURL.Path, "/")
	f.name = pathTokens[len(pathTokens)-1]

	dispHeader := c.header.Get("content-disposition")
	if dispHeader != "" {
		_, mimeParams, err := mime.ParseMediaType(dispHeader)
		if err == nil {
			filename := mimeParams["filename"]
			if filename != "" {
				f.name = filename
			}
		}
	}

	return f, nil
}
1210254
func Open(path string) (segment.Segment, error) {
	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	mm, err := mmap.Map(f, mmap.RDONLY, 0)
	if err != nil {
		// mmap failed, try to close the file
		_ = f.Close()
		return nil, err
	}

	rv := &Segment{
		SegmentBase: SegmentBase{
			mem:            mm[0 : len(mm)-FooterSize],
			fieldsMap:      make(map[string]uint16),
			fieldDvReaders: make(map[uint16]*docValueReader),
			fieldFSTs:      make(map[uint16]*vellum.FST),
		},
		f:    f,
		mm:   mm,
		path: path,
		refs: 1,
	}
	rv.SegmentBase.updateSize()

	err = rv.loadConfig()
	if err != nil {
		_ = rv.Close()
		return nil, err
	}

	err = rv.loadFields()
	if err != nil {
		_ = rv.Close()
		return nil, err
	}

	err = rv.loadDvReaders()
	if err != nil {
		_ = rv.Close()
		return nil, err
	}

	return rv, nil
}
1358548
func (i *Item) Open() (io.ReadCloser, error) {
	res, err := i.client.Objects.Get(i.container.name, i.name).Download()
	if err != nil {
		return nil, err
	}

	return res.Body, nil
}
1193232
func (h *fs) Open(filename string) (io.ReadCloser, error) {
	return os.Open(filename)
}
879258
func (c *CloudStorage) Open(ctx context.Context, path string) (*File, error) {
	bh, err := c.bucketHandle(ctx, storage.ScopeReadOnly)
	if err != nil {
		return nil, err
	}

	obj := bh.Object(path)
	attrs, err := obj.Attrs(ctx)
	if err != nil {
		if err == storage.ErrObjectNotExist {
			return nil, &notExistError{
				Path: path,
			}
		}
		return nil, fmt.Errorf("cloud storage: error fetching object attributes: %v", err)
	}

	r, err := obj.NewReader(ctx)
	if err != nil {
		return nil, fmt.Errorf("cloud storage: error fetching object reader for '%v': %v", path, err)
	}

	return &File{
		ReadCloser: r,
		Name:       attrs.Name,
		ModTime:    attrs.Updated,
		Size:       attrs.Size,
	}, nil
}