// Open initializes children recursively and "childrenResults" according to children's schemas.
422421
func (e *baseExecutor) Open(ctx context.Context) error {
	for _, child := range e.children {
		err := child.Open(ctx)
		if err != nil {
			return err
		}
	}
	return nil
}
796777
func (f *Field) Open() error {
	if err := func() error {
		// Ensure the field's path exists.
		f.logger.Debugf("ensure field path exists: %s", f.path)
		if err := os.MkdirAll(f.path, 0777); err != nil {
			return errors.Wrap(err, "creating field dir")
		}

		f.logger.Debugf("load meta file for index/field: %s/%s", f.index, f.name)
		if err := f.loadMeta(); err != nil {
			return errors.Wrap(err, "loading meta")
		}

		f.logger.Debugf("load available shards for index/field: %s/%s", f.index, f.name)
		if err := f.loadAvailableShards(); err != nil {
			return errors.Wrap(err, "loading available shards")
		}

		// Apply the field options loaded from meta.
		f.logger.Debugf("apply options for index/field: %s/%s", f.index, f.name)
		if err := f.applyOptions(f.options); err != nil {
			return errors.Wrap(err, "applying options")
		}

		f.logger.Debugf("open views for index/field: %s/%s", f.index, f.name)
		if err := f.openViews(); err != nil {
			return errors.Wrap(err, "opening views")
		}

		f.logger.Debugf("open row attribute store for index/field: %s/%s", f.index, f.name)
		if err := f.rowAttrStore.Open(); err != nil {
			return errors.Wrap(err, "opening attrstore")
		}

		return nil
	}(); err != nil {
		f.Close()
		return err
	}

	f.logger.Debugf("successfully opened field index/field: %s/%s", f.index, f.name)
	return nil
}
1122565
func (e *TableReaderExecutor) Open(ctx context.Context) error {
	var err error
	if e.corColInFilter {
		e.dagPB.Executors, _, err = constructDistExec(e.ctx, e.plans)
		if err != nil {
			return err
		}
	}
	if e.runtimeStats != nil {
		collExec := true
		e.dagPB.CollectExecutionSummaries = &collExec
	}
	if e.corColInAccess {
		ts := e.plans[0].(*plannercore.PhysicalTableScan)
		access := ts.AccessCondition
		pkTP := ts.Table.GetPkColInfo().FieldType
		e.ranges, err = ranger.BuildTableRange(access, e.ctx.GetSessionVars().StmtCtx, &pkTP)
		if err != nil {
			return err
		}
	}

	e.resultHandler = &tableResultHandler{}
	if e.feedback != nil && e.feedback.Hist != nil {
		// EncodeInt don't need *statement.Context.
		e.ranges = e.feedback.Hist.SplitRange(nil, e.ranges, false)
	}
	firstPartRanges, secondPartRanges := splitRanges(e.ranges, e.keepOrder, e.desc)
	firstResult, err := e.buildResp(ctx, firstPartRanges)
	if err != nil {
		e.feedback.Invalidate()
		return err
	}
	if len(secondPartRanges) == 0 {
		e.resultHandler.open(nil, firstResult)
		return nil
	}
	var secondResult distsql.SelectResult
	secondResult, err = e.buildResp(ctx, secondPartRanges)
	if err != nil {
		e.feedback.Invalidate()
		return err
	}
	e.resultHandler.open(firstResult, secondResult)
	return nil
}
466165
func (i *item) Open() (io.ReadCloser, error) {
	return os.Open(i.path)
}
848952
func (fl *FolderList) open(ctx context.Context, oc *openContext, path []string) (f dokan.File, cst dokan.CreateStatus, err error) {
	fl.fs.vlog.CLogf(ctx, libkb.VLog1, "FL Lookup %#v type=%s upper=%v",
		path, fl.tlfType, oc.isUppercasePath)
	if len(path) == 0 {
		return oc.returnDirNoCleanup(fl)
	}

	defer func() {
		fl.reportErr(ctx, libkbfs.ReadMode, tlf.CanonicalName(path[0]), err, nil)
	}()

	// TODO: A simple lower-casing is not good enough - see CORE-2967
	// However libkbfs does this too in tlf_handle.go...
	// The case of possible redirections will be ok, so we only need
	// to do this initially.
	if c := lowerTranslateCandidate(oc, path[0]); c != "" {
		path[0] = c
	}

	for oc.reduceRedirectionsLeft() {
		name := path[0]

		if name == "desktop.ini" || name == "DESKTOP.INI" {
			fl.fs.vlog.CLogf(ctx, libkb.VLog1, "FL Lookup ignoring desktop.ini")
			return nil, 0, dokan.ErrObjectNameNotFound
		}

		var aliasTarget string
		fl.mu.Lock()
		child, ok := fl.folders[name]
		if !ok {
			aliasTarget = fl.aliasCache[name]
		}
		fl.mu.Unlock()

		if ok {
			fl.fs.vlog.CLogf(
				ctx, libkb.VLog1, "FL Lookup recursing to child %q", name)
			return child.open(ctx, oc, path[1:])
		}

		if len(path) == 1 && isNewFolderName(name) {
			if !oc.isCreateDirectory() {
				return nil, 0, dokan.ErrObjectNameNotFound
			}
			fl.fs.vlog.CLogf(
				ctx, libkb.VLog1, "FL Lookup creating EmptyFolder for Explorer")
			e := &EmptyFolder{}
			fl.lockedAddChild(name, e)
			return e, dokan.NewDir, nil
		}

		if aliasTarget != "" {
			fl.fs.vlog.CLogf(
				ctx, libkb.VLog1, "FL Lookup aliasCache hit: %q -> %q",
				name, aliasTarget)
			if len(path) == 1 && oc.isOpenReparsePoint() {
				// TODO handle dir/non-dir here, semantics?
				return &Alias{canon: aliasTarget}, dokan.ExistingDir, nil
			}
			path[0] = aliasTarget
			continue
		}

		h, err := tlfhandle.ParseHandlePreferredQuick(
			ctx, fl.fs.config.KBPKI(), fl.fs.config, name, fl.tlfType)
		fl.fs.vlog.CLogf(
			ctx, libkb.VLog1, "FL Lookup continuing -> %v,%v", h, err)
		switch e := errors.Cause(err).(type) {
		case nil:
			// no error

		case idutil.TlfNameNotCanonical:
			// Only permit Aliases to targets that contain no errors.
			aliasTarget = e.NameToTry
			fl.fs.vlog.CLogf(
				ctx, libkb.VLog1, "FL Lookup set alias: %q -> %q",
				name, aliasTarget)
			if !fl.isValidAliasTarget(ctx, aliasTarget) {
				fl.fs.log.CDebugf(ctx, "FL Refusing alias to non-valid target %q", aliasTarget)
				return nil, 0, dokan.ErrObjectNameNotFound
			}
			fl.mu.Lock()
			fl.aliasCache[name] = aliasTarget
			fl.mu.Unlock()

			if len(path) == 1 && oc.isOpenReparsePoint() {
				// TODO handle dir/non-dir here, semantics?
				fl.fs.vlog.CLogf(
					ctx, libkb.VLog1, "FL Lookup ret alias, oc: %#v",
					oc.CreateData)
				return &Alias{canon: aliasTarget}, dokan.ExistingDir, nil
			}
			path[0] = aliasTarget
			continue

		case idutil.NoSuchNameError, idutil.BadTLFNameError:
			return nil, 0, dokan.ErrObjectNameNotFound

		default:
			// Some other error.
			return nil, 0, err
		}

		fl.fs.vlog.CLogf(ctx, libkb.VLog1, "FL Lookup adding new child")
		session, err := idutil.GetCurrentSessionIfPossible(ctx, fl.fs.config.KBPKI(), h.Type() == tlf.Public)
		if err != nil {
			return nil, 0, err
		}
		child = newTLF(fl, h, h.GetPreferredFormat(session.Name))
		fl.lockedAddChild(name, child)
		return child.open(ctx, oc, path[1:])
	}
	return nil, 0, dokan.ErrObjectNameNotFound
}
147200
func (e *LimitExec) Open(ctx context.Context) error {
	if err := e.baseExecutor.Open(ctx); err != nil {
		return err
	}
	e.childResult = e.children[0].newFirstChunk()
	e.cursor = 0
	e.meetFirstBatch = e.begin == 0
	return nil
}
561017
func (m *Multi) Open(name string) (io.ReadCloser, error) {
	for _, loader := range m.loaders {
		if f, err := loader.Open(name); err == nil {
			return f, nil
		}
	}
	return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
}
254004
func (e *SortExec) Open(ctx context.Context) error {
	e.fetched = false
	e.Idx = 0

	// To avoid duplicated initialization for TopNExec.
	if e.memTracker == nil {
		e.memTracker = memory.NewTracker(e.id, e.ctx.GetSessionVars().MemQuotaSort)
		e.memTracker.AttachTo(e.ctx.GetSessionVars().StmtCtx.MemTracker)
	}
	return e.children[0].Open(ctx)
}
984212
func Open(driverName, dataSourceName string) (*DB, error) {
	db, err := sql.Open(driverName, dataSourceName)
	if err != nil {
		return nil, err
	}
	return &DB{DB: db, driverName: driverName, Mapper: mapper()}, err
}
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
}
1261823
func (controller *LocalController) Open(ctx context.Context) error {
	// find all keyspace directories.
	fileInfos, err := ioutil.ReadDir(controller.schemaChangeDir)
	if err != nil {
		return err
	}
	for _, fileinfo := range fileInfos {
		if !fileinfo.IsDir() {
			continue
		}
		dirpath := path.Join(controller.schemaChangeDir, fileinfo.Name())
		schemaChanges, err := ioutil.ReadDir(path.Join(dirpath, "input"))
		if err != nil {
			log.Warningf("there is no input dir in %s", dirpath)
			continue
		}
		// found a schema change
		if len(schemaChanges) > 0 {
			controller.keyspace = fileinfo.Name()
			controller.sqlFilename = schemaChanges[0].Name()
			controller.sqlPath = path.Join(dirpath, "input", schemaChanges[0].Name())

			currentTime := time.Now()
			datePart := fmt.Sprintf(
				"%d/%d/%d",
				currentTime.Year(),
				currentTime.Month(),
				currentTime.Day())

			controller.errorDir = path.Join(dirpath, "error", datePart)
			controller.completeDir = path.Join(dirpath, "complete", datePart)
			controller.logDir = path.Join(dirpath, "log", datePart)
			// the remaining schema changes will be picked by the next runs
			break
		}
	}
	return nil
}
954078
func (e *SelectionExec) Open(ctx context.Context) error {
	if err := e.baseExecutor.Open(ctx); err != nil {
		return err
	}
	e.childResult = e.children[0].newFirstChunk()
	e.batched = expression.Vectorizable(e.filters)
	if e.batched {
		e.selected = make([]bool, 0, chunk.InitialCapacity)
	}
	e.inputIter = chunk.NewIterator4Chunk(e.childResult)
	e.inputRow = e.inputIter.End()
	return nil
}
1286908
func (s *KVStore) Open(ctx context.Context) error {
	// Ensure the required directory structure exists.
	if err := os.MkdirAll(filepath.Dir(s.path), 0700); err != nil {
		return fmt.Errorf("unable to create directory %s: %v", s.path, err)
	}

	if _, err := os.Stat(s.path); err != nil && !os.IsNotExist(err) {
		return err
	}

	// Open database file.
	db, err := bolt.Open(s.path, 0600, &bolt.Options{Timeout: 1 * time.Second})
	if err != nil {
		return fmt.Errorf("unable to open boltdb file %v", err)
	}
	s.db = db

	s.logger.Info("Resources opened", zap.String("path", s.path))
	return nil
}
567897
func (adapter *SQLiteAdapter) Open(dbURL string) (*sql.DB, error) {
	db, err := sql.Open("sqlite3", dbURL)
	if err != nil {
		adapter.Log.Info("msg", "Error creating database connection", "err", err)
		return nil, err
	}

	return db, nil
}
1329431
func (t *TeamBox) Open(encKey *libkb.NaclDHKeyPair) (keybase1.PerTeamKeySeed, error) {
	var ret keybase1.PerTeamKeySeed

	nonce, err := t.nonceBytes()
	if err != nil {
		return ret, err
	}
	ctext, err := t.ctextBytes()
	if err != nil {
		return ret, err
	}
	nei := &libkb.NaclEncryptionInfo{
		Ciphertext:     ctext,
		EncryptionType: kbcrypto.KIDNaclDH,
		Nonce:          nonce,
		Receiver:       encKey.GetKID().ToBytes(),
		Sender:         t.SenderKID.ToBytes(),
	}

	plaintext, _, err := encKey.Decrypt(nei)
	if err != nil {
		return ret, err
	}

	return libkb.MakeByte32Soft(plaintext)
}
59151
func (dbInst *DB) Open() {
	dbInst.mux.Lock()
	defer dbInst.mux.Unlock()
	if dbInst.dbState == opened {
		return
	}
	dbOpts := &opt.Options{}
	dbPath := dbInst.conf.DBPath
	var err error
	var dirEmpty bool
	if dirEmpty, err = util.CreateDirIfMissing(dbPath); err != nil {
		panic(fmt.Sprintf("Error creating dir if missing: %s", err))
	}
	dbOpts.ErrorIfMissing = !dirEmpty
	if dbInst.db, err = leveldb.OpenFile(dbPath, dbOpts); err != nil {
		panic(fmt.Sprintf("Error opening leveldb: %s", err))
	}
	dbInst.dbState = opened
}
20252
func (e *ReplaceExec) Open(ctx context.Context) error {
	if e.SelectExec != nil {
		return e.SelectExec.Open(ctx)
	}
	e.initEvalBuffer()
	return nil
}