// returns an opened file or nil if nothing to write.
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...)

}
857576
func LockedOpenFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
	return lockedOpenFile(path, flag, perm, syscall.F_SETLKW)
}
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
}
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
}
460296
func (t *File) reopenFile() error {
	t.fmu.Lock()
	defer t.fmu.Unlock()

	if t.file != nil {
		if err := t.file.Close(); err != nil {
			return err
		}
	}

	var err error
	t.file, err = os.OpenFile(t.filename, os.O_RDONLY, 0)
	switch {
	case os.IsNotExist(err):
		t.file = nil
	default:
		return err
	}

	return nil
}
39062
func GetWriteFile(url string, filename string, perm os.FileMode) ([]byte, error) {
	_, bytes, err := GetResponseAndBytes(url)
	if err != nil {
		return bytes, err
	}
	err = ioutil.WriteFile(filename, bytes, perm)
	return bytes, err
}
852361
func GetFileModeOfFile(pth string) (os.FileMode, error) {
	finfo, err := os.Lstat(pth)
	if err != nil {
		return 0, err
	}
	return finfo.Mode(), 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)
}
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)
}
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
}
988624
func (p *parserMixin) OpenFile(flag int, perm os.FileMode) (target **os.File) {
	target = new(*os.File)
	p.OpenFileVar(target, flag, perm)
	return
}
29260
func (s *Server) OpenFile(name string, mode int32) (File, error) {
	u := urlParse(name)

	if h, ok := s.schemes[u.Scheme]; ok {
		f, serr := h.Open(u, mode)
		if serr != os.ErrNotExist {
			return f, serr
		}
	}

	switch mode {
	case OpenModeReadOnly:
		return os.Open(filepath.Clean(name))
	case OpenModeWriteOnly:
		flag := os.O_WRONLY | os.O_CREATE | os.O_TRUNC
		return os.OpenFile(name, flag, 0600)
	default:
		return nil, &Status{
			Err:  fmt.Errorf("open mode(%d) not supported for file %q", mode, name),
			Code: StatusAccessDenied,
		}
	}
}
304373
func (fs *MockFilesystem) OpenFile(name string, flag int, perm os.FileMode) (file File, err error) {
	f, ok := fs.Files[name]
	if ok {
		f.Opened = true
		f.Closed = false
		return f, nil
	}
	return (*MockFile)(nil), &os.PathError{Err: errors.New(name + ": No such file.")}
}
195790
func Open(filename string) (*os.File, error) {
	return OpenFile(filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
}
556560
func (f *File) Open() (io.Reader, error) {
	if f.ino.Mode&ifmt != ifreg {
		return nil, fmt.Errorf("not a regular file")
	}
	return &fileReader{f, 0}, nil
}
1268763
func File() string {
	f := os.Getenv("CSEARCHINDEX")
	if f != "" {
		return f
	}
	var home string
	home = os.Getenv("HOME")
	if runtime.GOOS == "windows" && home == "" {
		home = os.Getenv("USERPROFILE")
	}
	return filepath.Clean(home + "/.csearchindex")
}
574518
func ReadFileOrFail(fn string) (res string) {
	var err error
	res, err = ReadFile(fn)
	if err != nil {
		log.Fatalf("ERROR: %v\n", err.Error())
	}
	return
}