// OpenSequential opens the named file for reading. If successful, methods on
// the returned file can be used for reading; the associated file
// descriptor has mode O_RDONLY.
// If there is an error, it will be of type *PathError.
779171
func OpenSequential(name string) (*os.File, error) {
	return OpenFileSequential(name, os.O_RDONLY, 0)
}
345495
func (f *File) Open() (io.ReadCloser, error) {
	return f.img.wim.resourceReader(&f.offset)
}
742585
func OpenFile(filename string) (*File, error) {
	content, err := readFile(filename)
	if err != nil {
		return nil, err
	}

	f := CreateFile(filepath.Base(filename), content)

	return f, nil
}
535783
func ReadIgnoreFile(filename string) ([]string, error) {
	igrd, err := os.Open(filename)
	if err != nil {
		//if os.IsNotExist(err){
		//    return []string{}, nil
		//}
		return nil, err
	}
	return ReadIgnore(igrd)
}
1154631
func OpenShardedIndex(path string) (ShardedIndex, error) {
	var meta shardedIndexMetadata
	var err error
	if err = readJSON(shardedIndexMetadataPath(path), &meta); err != nil {
		return nil, err
	}

	s := &shardedIndex{
		indices: make([]bleve.Index, meta.NumShards),
	}
	for i := 0; i < meta.NumShards; i++ {
		s.indices[i], err = bleve.Open(childIndexerPath(path, i))
		if err != nil {
			return nil, err
		}
	}
	s.bleveIndex = bleve.NewIndexAlias(s.indices...)
	return s, nil
}
1248946
func OpenFile(path string) error {
	logFilePath = path

	var err error
	logFile, err = os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		return err
	}

	SetOutput(logFile)
	return nil
}
30344
func (d Dir) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
	if name = d.resolve(name); name == "" {
		return nil, os.ErrNotExist
	}
	f, err := os.OpenFile(name, flag, perm)
	if err != nil {
		return nil, err
	}
	return f, nil
}
1132991
func (fs *FS) OpenFile(filename string, flag int, perm os.FileMode) (
	f billy.File, err error) {
	fs.log.CDebugf(
		fs.ctx, "OpenFile %s, flag=%d, perm=%o", filename, flag, perm)
	defer func() {
		fs.deferLog.CDebugf(fs.ctx, "OpenFile done: %+v", err)
		err = translateErr(err)
	}()

	if err := fs.requireNonEmpty(); err != nil {
		return nil, err
	}

	err = fs.ensureParentDir(filename)
	if err != nil {
		return nil, err
	}

	n, ei, err := fs.lookupOrCreateEntry(filename, flag, perm)
	if err != nil {
		return nil, err
	}

	// Make sure this is a file.
	if !ei.Type.IsFile() {
		return nil, errors.Errorf("%s is not a file", filename)
	}

	if flag&os.O_TRUNC != 0 {
		err := fs.config.KBFSOps().Truncate(fs.ctx, n, 0)
		if err != nil {
			return nil, err
		}
	}

	offset := int64(0)
	if flag&os.O_APPEND != 0 {
		if ei.Size >= uint64(1<<63) {
			return nil, errors.New("offset too large")
		}
		offset = int64(ei.Size)
	}

	return &File{
		fs:       fs,
		filename: filename,
		node:     n,
		readOnly: flag == os.O_RDONLY,
		offset:   offset,
	}, nil
}
480184
func (fs *FS) OpenFile(name string, flag int, perm os.FileMode) (vfs.File, error) {
	return fs.Filesystem.OpenFile(fs.PrefixPath(name), flag, perm)
}
1278045
func OpenFile(path string, perm os.FileMode, size int64) (*LogFile, error) {
	l := LogFile{}
	l.path = path
	l.perm = perm
	l.size = size
	l.rate = DefaultRotationRate

	// Search for the first available path
	err := l.searchFirstAvPath()
	if err != nil {
		return nil, err
	}
	// Open the file descriptor
	f, err := os.OpenFile(l.Path(), os.O_APPEND|os.O_CREATE|os.O_RDWR, l.perm)
	if err != nil {
		return nil, err
	}
	l.file = f
	l.writer = gzip.NewWriter(f)
	// We start the rotate routine
	l.rotateRoutine()
	return &l, nil
}
540786
func (i *Image) openDestinationsForWriting() (io.WriteCloser, error) {
	targetFilenames := i.targetFilenames()
	var changedFilenames []string

	// Fast path:
	// This is a processed version of the original;
	// check if it already existis at the destination.
	for _, targetFilename := range targetFilenames {
		if _, err := i.spec.BaseFs.PublishFs.Stat(targetFilename); err == nil {
			continue
		}
		changedFilenames = append(changedFilenames, targetFilename)
	}

	if len(changedFilenames) == 0 {
		return nil, nil
	}

	return helpers.OpenFilesForWriting(i.spec.BaseFs.PublishFs, changedFilenames...)

}
1373507
func (c *Client) Open(name string) (*FileReader, error) {
	info, err := c.getFileInfo(name)
	if err != nil {
		return nil, &os.PathError{"open", name, interpretException(err)}
	}

	return &FileReader{
		client: c,
		name:   name,
		info:   info,
		closed: false,
	}, nil
}
40765
func (fp FsPath) Open() (ReadCloser, error) {
	return fp.Fs.Open(fp.Path)
}
291176
func lockedOpenFile(path string, flag int, perm os.FileMode, lockType uint32) (*LockedFile, error) {
	f, err := Open(path, flag, perm)
	if err != nil {
		return nil, err
	}

	if err = lockFile(syscall.Handle(f.Fd()), lockType); err != nil {
		f.Close()
		return nil, err
	}

	st, err := os.Stat(path)
	if err != nil {
		f.Close()
		return nil, err
	}

	if st.IsDir() {
		f.Close()
		return nil, &os.PathError{
			Op:   "open",
			Path: path,
			Err:  syscall.EISDIR,
		}
	}

	return &LockedFile{File: f}, nil
}
1047682
func OpenDbForReadOnly(opts *Options, name string, errorIfLogFileExist bool) (*DB, error) {
	var (
		cErr  *C.char
		cName = C.CString(name)
	)
	defer C.free(unsafe.Pointer(cName))
	db := C.rocksdb_open_for_read_only(opts.c, cName, boolToChar(errorIfLogFileExist), &cErr)
	if cErr != nil {
		defer C.free(unsafe.Pointer(cErr))
		return nil, errors.New(C.GoString(cErr))
	}
	return &DB{
		name: name,
		c:    db,
		opts: opts,
	}, nil
}
1223420
func openLast(dirpath string) (*os.File, error) {
	names, err := fileutil.ReadDir(dirpath)
	if err != nil {
		return nil, err
	}
	names = checkWalNames(names)
	if len(names) == 0 {
		return nil, ErrFileNotFound
	}
	last := path.Join(dirpath, names[len(names)-1])
	return os.OpenFile(last, os.O_RDWR, 0)
}
564753
func (fs RoFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
	if flag&os.O_CREATE == os.O_CREATE {
		return nil, ErrReadOnly
	}
	if flag&os.O_APPEND == os.O_APPEND {
		return nil, ErrReadOnly
	}
	if flag&os.O_WRONLY == os.O_WRONLY {
		return nil, ErrReadOnly
	}
	f, err := fs.Filesystem.OpenFile(name, flag, perm)
	if err != nil {
		return ReadOnlyFile(f), err
	}
	return ReadOnlyFile(f), nil
}