// fixup goes through the output and improves the output generated by
// specific linters so that all output includes the relative path to the
// error, instead of mixing relative and absolute paths.
192827
func (r *result) fixup(dirname string) {
	for idx, ln := range r.output {
		if strings.HasPrefix(ln, dirname) {
			r.output[idx] = ln[len(dirname)+1:]
		}
	}
}
445199
func (g *Generator) Cleanup() {
	if len(g.genfiles) == 0 {
		return
	}
	os.RemoveAll(g.OutDir)
	g.genfiles = nil
}
982400
func (i *ImageService) Cleanup() {
	for os, ls := range i.layerStores {
		if ls != nil {
			if err := ls.Cleanup(); err != nil {
				logrus.Errorf("Error during layer Store.Cleanup(): %v %s", err, os)
			}
		}
	}
}
338381
func parseRemoteUpdateOutput(output string) []*mirrorSyncResult {
	results := make([]*mirrorSyncResult, 0, 3)
	lines := strings.Split(output, "\n")
	for i := range lines {
		// Make sure reference name is presented before continue
		idx := strings.Index(lines[i], "-> ")
		if idx == -1 {
			continue
		}

		refName := lines[i][idx+3:]
		switch {
		case strings.HasPrefix(lines[i], " * "): // New reference
			results = append(results, &mirrorSyncResult{
				refName:     refName,
				oldCommitID: GIT_SHORT_EMPTY_SHA,
			})
		case strings.HasPrefix(lines[i], " - "): // Delete reference
			results = append(results, &mirrorSyncResult{
				refName:     refName,
				newCommitID: GIT_SHORT_EMPTY_SHA,
			})
		case strings.HasPrefix(lines[i], "   "): // New commits of a reference
			delimIdx := strings.Index(lines[i][3:], " ")
			if delimIdx == -1 {
				log.Error(2, "SHA delimiter not found: %q", lines[i])
				continue
			}
			shas := strings.Split(lines[i][3:delimIdx+3], "..")
			if len(shas) != 2 {
				log.Error(2, "Expect two SHAs but not what found: %q", lines[i])
				continue
			}
			results = append(results, &mirrorSyncResult{
				refName:     refName,
				oldCommitID: shas[0],
				newCommitID: shas[1],
			})

		default:
			log.Warn("parseRemoteUpdateOutput: unexpected update line %q", lines[i])
		}
	}
	return results
}
1180714
func Clean(os, path string) string {
	abs := IsAbs(os, path)
	sep := Separator(os)
	elements := strings.Split(path, string(sep))

	// Replace multiple Separator elements with a single one.
	for i := 0; i < len(elements); i++ {
		if len(elements[i]) == 0 {
			elements = append(elements[:i], elements[i+1:]...)
			i--
		}
	}

	// Eliminate each . path name element (the current directory).
	for i := 0; i < len(elements); i++ {
		if elements[i] == "." && len(elements) > 1 {
			elements = append(elements[:i], elements[i+1:]...)
			i--
		}
	}

	// Eliminate each inner .. path name element (the parent directory)
	// along with the non-.. element that precedes it.
	for i := 1; i < len(elements); i++ {
		if i == 1 && abs && sep == '\\' {
			continue
		}
		if i > 0 && elements[i] == ".." {
			elements = append(elements[:i-1], elements[i+1:]...)
			i -= 2
		}
	}

	// Eliminate .. elements that begin a rooted path:
	// that is, replace "/.." by "/" at the beginning of a path,
	// assuming Separator is '/'.
	offset := 0
	if sep == '\\' {
		offset = 1
	}
	if abs {
		for len(elements) > offset && elements[offset] == ".." {
			elements = append(elements[:offset], elements[offset+1:]...)
		}
	}

	cleaned := strings.Join(elements, string(sep))
	if abs {
		if sep == '/' {
			cleaned = fmt.Sprintf("%c%s", sep, cleaned)
		} else if len(elements) == 1 {
			cleaned = fmt.Sprintf("%s%c", cleaned, sep)
		}
	}

	// If the result of this process is an empty string, Clean returns
	// the string ".".
	if len(cleaned) == 0 {
		cleaned = "."
	}

	if cleaned == path {
		return path
	}
	return Clean(os, cleaned)
}
583016
func main() {
	var (
		lintArgs       string
		lintBin        string
		packageList    string
		output         string
		packages       []string
		results        []*result
		hasFailingTest bool

		gopath = os.Getenv("GOPATH")
	)

	flag.StringVar(&lintArgs, "lintArgs", "", "args to pass to gometalinter")
	flag.StringVar(&lintBin, "lintBin", filepath.Join(gopath, "bin", "gometalinter"), "path to go metalinter")
	flag.StringVar(&packageList, "packages", "", "list of space separated packages")
	flag.StringVar(&output, "output", "", "output file for to write results.")
	flag.Parse()

	packages = strings.Split(strings.Replace(packageList, "-", "/", -1), " ")
	dirname, _ := os.Getwd()
	cwd := filepath.Base(dirname)
	gopath, _ = filepath.Abs(gopath)
	lintArgs += fmt.Sprintf(" --concurrency=%d", runtime.NumCPU()/2)

	for _, pkg := range packages {
		args := []string{lintBin, lintArgs}
		if cwd == pkg {
			args = append(args, ".")
		} else {
			args = append(args, "./"+pkg)
		}

		startAt := time.Now()
		cmd := strings.Join(args, " ")
		out, err := exec.Command("sh", "-c", cmd).CombinedOutput()

		r := &result{
			cmd:      strings.Join(args, " "),
			name:     "lint-" + strings.Replace(pkg, "/", "-", -1),
			passed:   err == nil,
			duration: time.Since(startAt),
			output:   strings.Split(string(out), "\n"),
		}
		r.fixup(dirname)

		if !r.passed {
			hasFailingTest = true
		}

		results = append(results, r)
		fmt.Println(r)
	}

	if output != "" {
		f, err := os.Create(output)
		if err != nil {
			os.Exit(1)
		}
		defer func() {
			if err != f.Close() {
				panic(err)
			}
		}()

		for _, r := range results {
			f.WriteString(r.String() + "\n")
		}
	}

	if hasFailingTest {
		os.Exit(1)
	}
}
1343407
func fixEnding(r io.Reader) ([]byte, error) {
	// read
	buf, err := ioutil.ReadAll(r)
	if err != nil {
		return nil, err
	}

	// add '\n' to end if not present
	if len(buf) == 0 || buf[len(buf)-1] != '\n' {
		return append(buf, '\n'), nil
	}
	return buf, nil
}
493427
func Fix(c *cli.Context) {
	hostsfile := AlwaysLoadHostFile(c)
	if bytes.Equal(hostsfile.GetData(), hostsfile.Format()) {
		MaybePrintln(c, fmt.Sprintf("%s is already formatted and contains no dupes or conflicts; nothing to do", GetHostsPath()))
		os.Exit(0)
	}
	MaybeSaveHostFile(c, hostsfile)
}
200780
func (s *Service) FixBuilds() *FixBuildsCall {
	c := &FixBuildsCall{s: s, urlParams_: make(gensupport.URLParams)}
	return c
}
1023487
func (spec MutateInSpec) Replace(path string, val interface{}, opts *MutateInSpecReplaceOptions) MutateInOp {
	if opts == nil {
		opts = &MutateInSpecReplaceOptions{}
	}
	var flags SubdocFlag
	if opts.IsXattr {
		flags |= SubdocFlagXattr
	}

	encoder := opts.Encoder
	if opts.Encoder == nil {
		encoder = JSONEncode
	}

	marshaled, _, err := encoder(val)
	if err != nil {
		return MutateInOp{err: err}
	}

	op := gocbcore.SubDocOp{
		Op:    gocbcore.SubDocOpReplace,
		Path:  path,
		Flags: gocbcore.SubdocFlag(flags),
		Value: marshaled,
	}

	return MutateInOp{op: op}
}
291415
func fixLineEnding(line string) (string, error) {
	if len(line) == 0 {
		return "", fmt.Errorf("line is blank")
	}

	if len(line) == 1 {
		if line[0] == '\n' {
			return "\r\n", nil
		}

		return "", fmt.Errorf("line does not end with LF")
	}

	lastIndex := len(line) - 1
	secondLastIndex := lastIndex - 1

	if line[secondLastIndex] == '\r' && line[lastIndex] == '\n' {
		return line, nil
	}

	if line[lastIndex] == '\n' {
		return line[:lastIndex] + "\r\n", nil
	}

	return "", fmt.Errorf("line has no ending CRLF or LF")
}
795255
func Clean(output string, err error) (string, error) {
	output = strings.Replace(strings.Split(output, "\n")[0], "'", "", -1)
	if err != nil {
		err = errors.New(strings.TrimSuffix(err.Error(), "\n"))
	}
	return output, err
}
596245
func fixTxtLines(line string) string {
	fields := strings.Fields(line)

	if len(fields) < 6 || fields[1] != "TXT" {
		return line
	}

	if fields[3][0] == '"' && fields[4] == `"` {
		fields[3] = strings.TrimSpace(fields[3]) + `"`
		fields = append(fields[:4], fields[5:]...)
	}

	return strings.Join(fields, " ")
}
658573
func (d *Driver) Cleanup() error {
	logrus.Infof("Stopping libchainfs at %s", virtPath)
	C.stop_chainfs()
	return nil
}
590940
func (p *provisioner) Output(output string) {
	logFile := path.Join(logfileDir, p.NodeName)
	f, err := os.OpenFile(logFile, os.O_APPEND|os.O_WRONLY, 0666)
	if err != nil {
		log.Printf("Error creating logfile %s: %v", logFile, err)
		return
	}
	defer f.Close()

	// These steps are needed to remove any ANSI escape codes used to colorize
	// the output and to make sure we have proper line endings before writing
	// the string to the logfile.
	re := regexp.MustCompile(`\x1b\[[0-9;]+m`)
	output = re.ReplaceAllString(output, "")
	output = strings.Replace(output, "\r", "\n", -1)

	if _, err := f.WriteString(output); err != nil {
		log.Printf("Error writing output to logfile %s: %v", logFile, err)
	}

	if err := f.Sync(); err != nil {
		log.Printf("Error saving logfile %s to disk: %v", logFile, err)
	}
}
1040674
func (d *distrib) Clean() error {
	for _, c := range d.caches {
		c.Clean()
	}
	return nil
}
1222936
func makeAbsolute(inputFilePath, outputFilePath string) (string, string, error) {
	inputFilePath, err := filepath.Abs(inputFilePath)
	if err == nil {
		outputFilePath, err = filepath.Abs(outputFilePath)
	}

	return inputFilePath, outputFilePath, err
}