// Processes given path. If the target is a file, it is stored in the file list. If the target
// is a directory, function is called recursively on nested paths in order to process the whole tree.
343851
func (fsh *Handler) getFilesInPath(files []string, path string) error {
	pathInfo, err := os.Stat(path)
	if err != nil {
		return errors.Errorf("failed to read path %s: %v", path, err)
	}
	if pathInfo.IsDir() {
		pathList, err := ioutil.ReadDir(path)
		if err != nil {
			return errors.Errorf("failed to read directory %s: %v", path, err)
		}
		for _, nested := range pathList {
			// Recursive call to process all the tree
			if err := fsh.getFilesInPath(files, path+nested.Name()); err != nil {
				return err
			}
		}
	}
	files = append(files, path)

	return nil
}
917654
func (prc ListProcessor) Process(nim image.Image, params imageserver.Params) (image.Image, error) {
	for _, p := range prc {
		var err error
		nim, err = p.Process(nim, params)
		if err != nil {
			return nil, err
		}
	}
	return nim, nil
}
713165
func (ssc *ScssSassCompiler) Process(content []byte, path string) ([]byte, error) {
	in := bytes.NewBuffer(content)
	out := &bytes.Buffer{}
	comp, err := libsass.New(out, in, libsass.OutputStyle(libsass.Style["nested"]), libsass.Comments(ssc.LineNumbers || ssc.DebugInfo))
	if err != nil {
		return nil, err
	}
	if err := comp.Run(); err != nil {
		return nil, err
	}
	return bytes.TrimSpace(bytes.Replace(out.Bytes(), []byte("*filecompiler.SassCompiler"), make([]byte, 0), 1)), nil
}
405615
func (a *ReverseNestedAggregation) Path(path string) *ReverseNestedAggregation {
	a.path = path
	return a
}
22854
func (o *Opts) Process(args []string) error {

	//cannot be processed - already encountered error - programmer error
	if o.erred != nil {
		return fmt.Errorf("[opts] Process error: %s", o.erred)
	}

	//1. set config via JSON file
	if o.cfgPath != "" {
		b, err := ioutil.ReadFile(o.cfgPath)
		if err == nil {
			v := o.val.Interface() //*struct
			err = json.Unmarshal(b, v)
			if err != nil {
				o.erred = fmt.Errorf("Invalid config file: %s", err)
				return errors.New(o.Help())
			}
		}
	}

	flagset := flag.NewFlagSet(o.name, flag.ContinueOnError)
	flagset.SetOutput(ioutil.Discard)

	//pre-loop through the options and
	//add shortnames and env names where possible
	for _, opt := range o.opts {
		//should generate shortname?
		if len(opt.name) >= 3 && opt.shortName == "" {
			//not already taken?
			if s := opt.name[0:1]; !o.optnames[s] {
				opt.shortName = s
				o.optnames[s] = true
			}
		}
		env := camel2const(opt.name)
		if o.useEnv && (opt.envName == "" || opt.envName == "!") &&
			opt.name != "help" && opt.name != "version" &&
			!o.envnames[env] {
			opt.envName = env
		}
	}

	for _, opt := range o.opts {
		// TODO remove debug
		// log.Printf("parse prepare option: %s", opt.name)

		//2. set config via environment
		envVal := ""
		if opt.useEnv || o.useEnv {
			envVal = os.Getenv(opt.envName)
		}
		//3. set config via Go's pkg/flags
		addr := opt.val.Addr().Interface()
		switch addr := addr.(type) {
		case flag.Value:
			flagset.Var(addr, opt.name, "")
			if opt.shortName != "" {
				flagset.Var(addr, opt.shortName, "")
			}
		case *[]string:
			sep := ""
			switch opt.typeName {
			case "commalist":
				sep = ","
			case "spacelist":
				sep = " "
			}
			fv := &sepList{sep: sep, strs: addr}
			flagset.Var(fv, opt.name, "")
			if opt.shortName != "" {
				flagset.Var(fv, opt.shortName, "")
			}
		case *bool:
			str2bool(envVal, addr)
			flagset.BoolVar(addr, opt.name, *addr, "")
			if opt.shortName != "" {
				flagset.BoolVar(addr, opt.shortName, *addr, "")
			}
		case *string:
			str2str(envVal, addr)
			flagset.StringVar(addr, opt.name, *addr, "")
			if opt.shortName != "" {
				flagset.StringVar(addr, opt.shortName, *addr, "")
			}
		case *int:
			str2int(envVal, addr)
			flagset.IntVar(addr, opt.name, *addr, "")
			if opt.shortName != "" {
				flagset.IntVar(addr, opt.shortName, *addr, "")
			}
		case *time.Duration:
			flagset.DurationVar(addr, opt.name, *addr, "")
			if opt.shortName != "" {
				flagset.DurationVar(addr, opt.shortName, *addr, "")
			}
		default:
			return fmt.Errorf("[opts] Option '%s' has unsupported type", opt.name)
		}
	}

	// log.Printf("parse %+v", args)
	//set user config
	err := flagset.Parse(args)
	if err != nil {
		//insert flag errors into help text
		o.erred = err
		o.internalOpts.Help = true
	}

	//internal opts (--help and --version)
	if o.internalOpts.Help {
		return errors.New(o.Help())
	} else if o.internalOpts.Version {
		fmt.Println(o.version)
		os.Exit(0)
	}

	//fill each individual arg
	args = flagset.Args()
	for i, argument := range o.args {
		if len(args) > 0 {
			str := args[0]
			args = args[1:]
			argument.val.SetString(str)
		} else if argument.defstr == "" {
			//not-set and no default!
			o.erred = fmt.Errorf("Argument #%d '%s' has no default value", i+1, argument.name)
			return errors.New(o.Help())
		}
	}

	//use command? peek at args
	if len(o.cmds) > 0 && len(args) > 0 {
		a := args[0]
		//matching command, use it
		if sub, exists := o.cmds[a]; exists {
			//user wants name to be set
			if o.cmdname != nil {
				o.cmdname.SetString(a)
			}
			return sub.Process(args[1:])
		}
	}

	//fill arglist? assign remaining as slice
	if o.arglist != nil {
		if len(args) < o.arglist.min {
			o.erred = fmt.Errorf("Too few arguments (expected %d, got %d)", o.arglist.min, len(args))
			return errors.New(o.Help())
		}
		o.arglist.val.Set(reflect.ValueOf(args))
		args = nil
	}

	//we *should* have consumed all args at this point.
	//this prevents:  ./foo --bar 42 -z 21 ping --pong 7
	//where --pong 7 is ignored
	if len(args) != 0 {
		o.erred = fmt.Errorf("Unexpected arguments: %+v", args)
		return errors.New(o.Help())
	}

	return nil
}
525280
func Paths(path string, recurse bool) (paths []string, err error) {
	err = filepath.Walk(path, func(f string, info os.FileInfo, err error) error {
		if !recurse {
			if path != f && path != filepath.Dir(f) {
				return filepath.SkipDir
			}
		}
		paths = append(paths, f)
		return nil
	})
	return paths, err
}
1174109
func (d *document) Process(processor ValueProcessor) error {
	return process(d.root, []string{}, d.separator, processor)
}
95546
func Init() {
	// Root path is automatically determined from the calling function's source file location.
	// Catch the calling function's source file path.
	_, file, _, _ := runtime.Caller(1)
	// Save the directory alone.
	rootPath = filepath.Dir(file)

	appInfo = make(map[string]string)
}
72781
func Process(pkg, outdir string, newType string, optset ...func(*Options)) error {
	opts := DefaultOptions
	for _, fn := range optset {
		fn(&opts)
	}

	p, err := findPackage(pkg)
	if err != nil {
		return err
	}

	if outdir == "" {
		outdir = path.Base(pkg)
	}

	if err := os.MkdirAll(outdir, os.ModePerm); err != nil {
		return err
	}

	t := parseTargetType(newType)

	files, err := processFiles(p, p.GoFiles, t)
	if err != nil {
		return err
	}

	if err := write(outdir, files); err != nil {
		return err
	}

	if opts.SkipTestFiles {
		return nil
	}

	files, err = processFiles(p, p.TestGoFiles, t)
	if err != nil {
		return err
	}

	return write(outdir, files)
}
672790
func (g *Globber) filepaths(list []string, dir string, tree bool) (r []string) {
	var dirsep string
	if dir != "" {
		dirsep = dir + string(g.config.Separator)
		i := sort.SearchStrings(list, dirsep)
		if i >= len(list) {
			return
		}
		list = list[i:]
	}
	found := map[string]struct{}{}
	for _, path := range list {
		if dirsep != "" && !strings.HasPrefix(path, dirsep) {
			break
		}
		for j := len(dirsep); j < len(path); j++ {
			for j < len(path) && path[j] != g.config.Separator {
				j++
			}
			path := path[:j]
			if _, ok := found[path]; !ok {
				found[path] = struct{}{}
				r = append(r, path)
			}
			if !tree {
				break
			}
		}
	}
	return
}
393364
func (pruner *Pruner) Prune(baseFilePath string) {
	if pruner.pruneHours > 0 {
		pruner.pruneByHour(baseFilePath, pruner.pruneHours)
	}
	if pruner.pruneCount > 0 {
		pruner.pruneByCount(baseFilePath, pruner.pruneCount)
	}
	if pruner.pruneSize > 0 {
		pruner.pruneToSize(baseFilePath, pruner.pruneSize)
	}
}
499884
func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error) {
	p := &Process{
		id: id,
		t:  t,
	}
	if _, err := p.State(ctx); err != nil {
		return nil, err
	}
	return p, nil
}
853360
func (u *Update) Target(path string) *Update {
	u.TargetPath = path
	return u
}
705280
func (l *Linode) Process() ([]*Response, error) {
	// Quickly handle the case where we have zero or one actions to perform.
	count := len(l.actions)
	if count == 0 {
		return nil, NewError(errors.New("linode: request must contain at least one action"))
	}
	defer l.Reset()
	if count == 1 {
		resp, err := l.Request(l.actions[0].parameters.Get(apiAction), l.actions[0].parameters, l.actions[0].result)
		if resp == nil {
			return nil, err
		}
		return []*Response{resp}, err
	}

	// Prepare the parameters.
	params := make([]Parameters, 0, len(l.actions))
	for _, action := range l.actions {
		params = append(params, action.parameters)
	}
	jsonParams, err := json.Marshal(params)
	if err != nil {
		return nil, NewError(err)
	}

	// Initialize the request.
	req, err := http.NewRequest("GET", l.apiEndpoint, nil)
	if err != nil {
		return nil, NewError(err)
	}
	query := Parameters{
		apiKey:          l.apiKey,
		apiAction:       "batch",
		apiRequestArray: string(jsonParams),
	}
	req.URL.RawQuery = query.Encode()

	// Do the request.
	resp, err := client.Do(req)
	if err != nil {
		return nil, NewError(err)
	}
	defer resp.Body.Close()

	// Decode the response.
	var response []*Response
	decoder := json.NewDecoder(resp.Body)
	if err = decoder.Decode(&response); err != nil {
		return nil, NewError(err)
	}

	// Decode the raw data into action-specific data.
	// FIXME: This whole block needs error handling, and I think since this
	// is handling multiple actions, it should probably handle errors on a
	// per-action basis.
	for index, action := range response {
		if l.actions[index].result == nil {
			continue
		}
		if err = json.Unmarshal(action.RawData, &l.actions[index].result); err != nil {
			continue
		}
		response[index].Data = l.actions[index].result
	}

	return response, nil
}
926066
func (c *ConfigPolicyNode) Process(m map[string]ctypes.ConfigValue) (*map[string]ctypes.ConfigValue, *ProcessingErrors) {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	pErrors := NewProcessingErrors()
	// Loop through each rule and process
	for key, rule := range c.rules {
		// items exists for rule
		if cv, ok := m[key]; ok {
			// Validate versus matching data
			e := rule.Validate(cv)
			if e != nil {
				pErrors.AddError(e)
			}
		} else {
			// If it was required add error
			if rule.Required() {
				e := fmt.Errorf("required key missing (%s)", key)
				pErrors.AddError(e)
			} else {
				// If default returns we should add it
				cv := rule.Default()
				if cv != nil {
					m[key] = cv
				}

			}
		}
	}

	if pErrors.HasErrors() {
		return nil, pErrors
	}
	return &m, pErrors
}
809427
func (gl *goLibrary) targetDir() string {
	baseDir := gl.parentDir
	if libraries.IsRemote(gl.Filename) {
		baseDir = gl.rootTargetDir
	}

	fileDir := goLibPackageDir(gl.name, libraries.StripLibRootURL(gl.Filename, gl.libRootURLs))

	return filepath.Join(baseDir, fileDir)
}
1154445
func (b *SinkHandler) process() {
	for {
		rec, ok := <-b.sinkCh
		if !ok {
			b.inner.Close()
			break
		}

		b.inner.Handle(rec)
	}
	b.wg.Done()
}