// checkDuplicateOutputFiles finds first non-unique Go file
764130
func checkDuplicateOutputFiles(fileNames []string) error {
	for i := range fileNames {
		ok, err := isGoFile(fileNames[i])
		if err != nil {
			return err
		}

		if !ok {
			continue
		}

		ipath, err := filepath.Abs(fileNames[i])
		if err != nil {
			return err
		}

		for j := range fileNames {
			jpath, err := filepath.Abs(fileNames[j])
			if err != nil {
				return err
			}

			if j != i && ipath == jpath {
				return errors.Errorf("duplicate output file name: %s", ipath)
			}
		}
	}

	return nil
}
531182
func (ut *UploadTracker) uploadFiles(files []*Item) error {
	// Handle the large individually-uploaded files.
	for _, item := range files {
		d, err := ut.hashFile(item.Path)
		if err != nil {
			return err
		}
		item.Digest = d
		ut.isol.Files[item.RelPath] = isolated.BasicFile(item.Digest, int(item.Mode), item.Size)
		ut.checker.AddItem(item, false, func(item *Item, ps *isolatedclient.PushState) {
			if ps == nil {
				return
			}

			// We are about to upload item. If we fail, the entire isolate operation will fail.
			// If we succeed, then item will be on the server by the time that the isolate operation
			// completes. So it is safe for subsequent checks to assume that the item exists.
			ut.checker.PresumeExists(item)

			log.Printf("QUEUED %q for upload", item.RelPath)
			ut.uploader.UploadFile(item, ps, func() {
				log.Printf("UPLOADED %q", item.RelPath)
			})
		})
	}
	return nil
}
1179091
func (k *SimpleFS) SimpleFSCopyRecursive(ctx context.Context,
	arg keybase1.SimpleFSCopyRecursiveArg) error {
	return k.startAsync(ctx, arg.OpID, keybase1.AsyncOps_COPY,
		keybase1.NewOpDescriptionWithCopy(
			keybase1.CopyArgs{OpID: arg.OpID, Src: arg.Src, Dest: arg.Dest}),
		func(ctx context.Context) (err error) {
			return k.doCopyRecursive(ctx, arg.OpID, arg.Src, arg.Dest)
		})
}
656440
func checkDuplicateFlags(current *CmdClause, flagGroups []*flagGroup) error {
	// Check for duplicates.
	for _, flags := range flagGroups {
		for _, flag := range current.flagOrder {
			if flag.shorthand != 0 {
				if _, ok := flags.short[string(flag.shorthand)]; ok {
					return fmt.Errorf("duplicate short flag -%c", flag.shorthand)
				}
			}
			if _, ok := flags.long[flag.name]; ok {
				return fmt.Errorf("duplicate long flag --%s", flag.name)
			}
		}
	}
	flagGroups = append(flagGroups, current.flagGroup)
	// Check subcommands.
	for _, subcmd := range current.commandOrder {
		if err := checkDuplicateFlags(subcmd, flagGroups); err != nil {
			return err
		}
	}
	return nil
}
182630
func PrintFilesOrFail(files []string, err error) {
	FailOnError(err)
	fmt.Println(strings.Join(files, "\n"))
}
370629
func (e *entry) deduplicate() {
	e.mu.Lock()
	defer e.mu.Unlock()

	if len(e.values) <= 1 {
		return
	}
	e.values = e.values.Deduplicate()
}
266862
func zipInputFiles(ctx context.Context, files []fs.File, w io.Writer, level int) error {
	logging.Infof(ctx, "About to zip %d files with compression level %d", len(files), level)

	writer := zip.NewWriter(w)
	defer writer.Close()

	writer.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
		return flate.NewWriter(out, level)
	})

	// Reports zipping progress to the log each second.
	lastReport := time.Time{}
	progress := func(count int) {
		if time.Since(lastReport) > time.Second {
			lastReport = time.Now()
			logging.Infof(ctx, "Zipping files: %d files left", len(files)-count)
		}
	}

	for i, in := range files {
		progress(i)

		// Bail out early if context is canceled.
		if err := ctx.Err(); err != nil {
			return err
		}

		// Intentionally do not add file mode to make zip archive
		// deterministic. Timestamps sometimes need to be preserved, but normally
		// are zero valued. See also zip.FileInfoHeader() implementation.
		fh := zip.FileHeader{
			Name:   in.Name(),
			Method: zip.Deflate,
		}
		if level == 0 || in.Symlink() || isLikelyAlreadyCompressed(in) {
			fh.Method = zip.Store
		}

		mode := os.FileMode(0400)
		if in.Executable() {
			mode |= 0100
		}
		if in.Writable() {
			mode |= 0200
		}
		if in.Symlink() {
			mode |= os.ModeSymlink
		}
		fh.SetMode(mode)

		if !in.ModTime().IsZero() {
			fh.SetModTime(in.ModTime())
		}

		fh.ExternalAttrs |= uint32(in.WinAttrs())

		dst, err := writer.CreateHeader(&fh)
		if err != nil {
			return err
		}
		if in.Symlink() {
			err = zipSymlinkFile(dst, in)
		} else {
			err = zipRegularFile(dst, in)
		}
		if err != nil {
			return err
		}
	}

	return nil
}
179499
func IsErrorDuplicateViolateUniqueConstraint(err error) bool {
	if ErrorDuplicateViolateUniqueConstraint.Match(err) {
		return true
	}
	switch e := err.(type) {
	case nil:
		return false
	case *pq.Error:
		return e.Code == "23505"
	case *mysql.MySQLError:
		return e.Number == 1062
	default:
		return strings.Contains(err.Error(), "pq: duplicate key value violates unique constraint")
	}
}
817815
func (c *Client) LinodeDiskDuplicate(linodeID int, diskID int) (jobID int, nDiskID int,
	err error) {

	args := make(map[string]interface{})
	args["LinodeID"] = linodeID
	args["DiskID"] = diskID

	data, err := c.apiCall("linode.disk.duplicate", args)
	if err != nil {
		return 0, 0, err
	}

	out := struct {
		JobID  int `json:"JobID"`
		DiskID int `json:"DiskID"`
	}{}

	err = json.Unmarshal(data, &out)
	if err != nil {
		return 0, 0, err
	}

	return out.JobID, out.DiskID, nil
}
594044
func Duplicate(field *Path, value interface{}) *Error {
	return &Error{ErrorTypeDuplicate, field.String(), value, ""}
}
1087717
func (s *StanServer) isDuplicateConnect(client *client) bool {
	client.RLock()
	hbInbox := client.info.HbInbox
	client.RUnlock()

	// This is the HbInbox from the "old" client. See if it is up and
	// running by sending a ping to that inbox.
	_, err := s.nc.Request(hbInbox, nil, s.dupCIDTimeout)

	// If err is nil, the currently registered client responded, so this is a
	// duplicate.
	return err == nil
}
433339
func writeOutputStream(output []string, outputFile string) error {
	var f *os.File

	if outputFile == "" {
		f = os.Stdout
	} else {
		var err error
		f, err = os.Create(outputFile)
		if err != nil {
			return err
		}
		defer f.Close()
	}

	for _, doc := range output {
		_, err := f.WriteString("---\n")
		if err != nil {
			return err
		}
		_, err = f.WriteString(doc)
		if err != nil {
			return err
		}
	}

	if len(output) > 0 {
		_, err := f.WriteString("...\n")
		if err != nil {
			return err
		}
	}

	return nil
}
1177509
func (s *Session) CombinedOutput(cmd string) ([]byte, error) {
	if s.Stdout != nil {
		return nil, errors.New("ssh: Stdout already set")
	}
	if s.Stderr != nil {
		return nil, errors.New("ssh: Stderr already set")
	}
	var b singleWriter
	s.Stdout = &b
	s.Stderr = &b
	err := s.Run(cmd)
	return b.b.Bytes(), err
}
173825
func (r Result) CombinedOutput() string {
	strs := []string{}
	if sout := r.Stdout.String(); sout != "" {
		strs = append(strs, fmt.Sprintf("[stdout]: %s", sout))
	}
	if serr := r.Stderr.String(); serr != "" {
		strs = append(strs, fmt.Sprintf("[stderr]: %s", serr))
	}
	return strings.Join(strs, ", ")
}
892753
func duplicates(value Project, arr []Project) (Project, error) {
	for _, val := range arr {
		if value.Name == val.Name {
			return val, errors.New("There is already a project with name '" + val.Name + "'. Check your config file!")
		}
	}
	return Project{}, nil
}
989416
func (w *CompoundFileWriter) copyFileEntry(dataOut IndexOutput, fileEntry *FileEntry) (n int64, err error) {
	var is IndexInput
	is, err = fileEntry.dir.OpenInput(fileEntry.file, IO_CONTEXT_READONCE)
	if err != nil {
		return 0, err
	}
	var success = false
	defer func() {
		if success {
			err = util.Close(is)
			// copy successful - delete file
			if err == nil {
				fileEntry.dir.DeleteFile(fileEntry.file) // ignore error
			}
		} else {
			util.CloseWhileSuppressingError(is)
		}
	}()

	startPtr := dataOut.FilePointer()
	length := fileEntry.length
	err = dataOut.CopyBytes(is, length)
	if err != nil {
		return 0, err
	}
	// verify that the output length diff is equal to original file
	endPtr := dataOut.FilePointer()
	diff := endPtr - startPtr
	if diff != length {
		return 0, errors.New(fmt.Sprintf(
			"Difference in the output file offsets %v does not match the original file length %v",
			diff, length))
	}
	fileEntry.offset = startPtr
	success = true
	return length, nil
}
760645
func dedupeStrings(s1, s2 []string) (r []string) {
	dedupe := make(map[string]bool)

	if len(s1) > 0 && len(s2) > 0 {
		for _, i := range s1 {
			dedupe[i] = true
		}
		for _, i := range s2 {
			dedupe[i] = true
		}

		for i := range dedupe {
			r = append(r, i)
		}
		// And then re-sort them
		sort.Strings(r)
	} else if len(s1) > 0 {
		r = s1
	} else if len(s2) > 0 {
		r = s2
	}

	return
}