// Open opens and initializes the Log. Open can recover from previous unclosed shutdowns.
169951
func (l *WAL) Open(ctx context.Context) error {
	l.mu.Lock()
	defer l.mu.Unlock()

	if !l.enabled {
		return nil
	}

	span, _ := tracing.StartSpanFromContext(ctx)
	defer span.Finish()

	span.LogKV("segment_size", l.SegmentSize,
		"path", l.path)

	// Initialise metrics for trackers.
	mmu.Lock()
	if wms == nil {
		wms = newWALMetrics(l.defaultMetricLabels)
	}
	mmu.Unlock()

	// Set the shared metrics for the tracker
	l.tracker = newWALTracker(wms, l.defaultMetricLabels)

	if err := os.MkdirAll(l.path, 0777); err != nil {
		return err
	}

	segments, err := SegmentFileNames(l.path)
	if err != nil {
		return err
	}
	l.tracker.SetSegments(uint64(len(segments)))

	if len(segments) > 0 {
		lastSegment := segments[len(segments)-1]
		id, err := idFromFileName(lastSegment)
		if err != nil {
			return err
		}

		l.currentSegmentID = id
		stat, err := os.Stat(lastSegment)
		if err != nil {
			return err
		}

		if stat.Size() == 0 {
			os.Remove(lastSegment)
			segments = segments[:len(segments)-1]
			l.tracker.DecSegments()
		} else {
			fd, err := os.OpenFile(lastSegment, os.O_RDWR, 0666)
			if err != nil {
				return err
			}
			if _, err := fd.Seek(0, io.SeekEnd); err != nil {
				return err
			}
			l.currentSegmentWriter = NewWALSegmentWriter(fd)

			// Reset the current segment size stat
			l.tracker.SetCurrentSegmentSize(uint64(stat.Size()))
		}
	}

	var totalOldDiskSize int64
	for _, seg := range segments {
		stat, err := os.Stat(seg)
		if err != nil {
			return err
		}

		if stat.Size() > 0 {
			totalOldDiskSize += stat.Size()
			if stat.ModTime().After(l.lastWriteTime) {
				l.lastWriteTime = stat.ModTime().UTC()
			}
		}
	}
	l.tracker.SetOldSegmentSize(uint64(totalOldDiskSize))

	l.closing = make(chan struct{})

	return nil
}
1193232
func (h *fs) Open(filename string) (io.ReadCloser, error) {
	return os.Open(filename)
}
739543
func Open(path string) (*ELF, error) {
	scopedLog := log.WithField(srcPath, path)

	f, err := os.Open(path)
	if err != nil {
		return nil, &os.PathError{
			Op:   "failed to open ELF file",
			Path: path,
			Err:  err,
		}
	}

	result, err := NewELF(f, scopedLog)
	if err != nil {
		if err2 := f.Close(); err2 != nil {
			scopedLog.WithError(err).Warning("Failed to close ELF")
		}
		return nil, &os.PathError{
			Op:   "failed to parse ELF file",
			Path: path,
			Err:  err,
		}
	}
	result.file = f
	return result, nil
}
256521
func (tlf *TLF) Open(ctx context.Context, req *fuse.OpenRequest,
	resp *fuse.OpenResponse) (fs.Handle, error) {
	// Explicitly load the directory when a TLF is opened, because
	// some OSX programs like ls have a bug that doesn't report errors
	// on a ReadDirAll.
	_, _, err := tlf.loadDirAllowNonexistent(ctx)
	if err != nil {
		return nil, err
	}
	return tlf, nil
}
196795
func Open(path string, mode os.FileMode, options *bolt.Options) (*DB, error) {
	bdb, err := bolt.Open(path, mode, options)
	if err != nil {
		return nil, err
	}

	return New(bdb), nil
}
483853
func (s *Stream) Open() (io.ReadCloser, error) {
	return s.wim.resourceReader(&s.offset)
}
1092037
func Open(name string) (int, error) {
	return open(name, syscall.IFF_TUN|syscall.IFF_NO_PI)
}
683998
func (h *ArchiveHandler) Open(u *url.URL, mode int32) (File, error) {
	switch mode {
	case OpenModeReadOnly:
		return h.newArchiveFromGuest(u)
	case OpenModeWriteOnly:
		return h.newArchiveToGuest(u)
	default:
		return nil, os.ErrNotExist
	}
}
294328
func (c *Client) Open(name string) *File {
	r, w := io.Pipe()
	return &File{
		Name:  name,
		c:     c,
		pipeR: r,
		pipeW: w,
	}
}
636361
func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
	return &callback{logger: logger, pathSuffix: "/" + id}, nil
}
886505
func (l *httpFileSystemLoader) Open(name string) (io.ReadCloser, error) {
	if l.fs == nil {
		return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
	}
	return l.fs.Open(name)
}
144550
func Open(path string) (*zip.Reader, error) {
	_, rd, err := OpenCloser(path)
	return rd, err
}
630944
func (s *TranslateFile) Open() (err error) {
	// Open writer & buffered writer.
	if err := os.MkdirAll(filepath.Dir(s.Path), 0777); err != nil {
		return errors.Wrapf(err, "mkdir %s", filepath.Dir(s.Path))
	} else if s.file, err = os.OpenFile(s.Path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666); err != nil {
		return errors.Wrapf(err, "open file %s", s.Path)
	}
	s.w = bufio.NewWriter(s.file)

	// Memory map data file.
	if s.data, err = syscall.Mmap(int(s.file.Fd()), 0, s.mapSize, syscall.PROT_READ, syscall.MAP_SHARED); err != nil {
		return errors.Wrapf(err, "creating Mmap (size: %d)", s.mapSize)
	}

	// Replay the log.
	if err := s.replayEntries(); err != nil {
		return errors.Wrap(err, "replaying log entries")
	}

	// Listen to primaryStoreEvents channel.
	s.wg.Add(1)
	go func() { defer s.wg.Done(); s.monitorPrimaryStoreEvents() }()

	return 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
}
144103
func (t *FileTarget) Open(errWriter io.Writer) error {
	t.Filter.Init()
	if t.FileName == "" {
		return errors.New("FileTarget.FileName must be set")
	}
	if t.Rotate {
		if t.BackupCount < 0 {
			return errors.New("FileTarget.BackupCount must be no less than 0")
		}
		if t.MaxBytes <= 0 {
			return errors.New("FileTarget.MaxBytes must be no less than 0")
		}
	}

	fd, err := os.OpenFile(t.FileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0660)
	if err != nil {
		return fmt.Errorf("FileTarget was unable to create a log file: %v", err)
	}
	t.fd = fd
	t.errWriter = errWriter

	return nil
}
1055497
func Open(c *Config) (p Port, err error) {
	p = New()
	err = p.Open(c)
	return
}
37848
func (f *Function) Open(environment string) error {
	f.defaults()

	f.Log = f.Log.WithFields(log.Fields{
		"function": f.Name,
		"env":      environment,
	})

	f.Log.Debug("open")

	if err := f.loadConfig(environment); err != nil {
		return errors.Wrap(err, "loading config")
	}

	if err := f.hookOpen(); err != nil {
		return errors.Wrap(err, "open hook")
	}

	if err := validator.Validate(&f.Config); err != nil {
		return errors.Wrap(err, "validating")
	}

	ignoreFile, err := utils.ReadIgnoreFile(f.Path)
	if err != nil {
		return errors.Wrap(err, "reading ignore file")
	}

	f.IgnoreFile = append(f.IgnoreFile, []byte("\n")...)
	f.IgnoreFile = append(f.IgnoreFile, ignoreFile...)

	return nil
}