// ADD foo /path
//
// Add the file 'foo' to '/path'. Tarball and Remote URL (git, http) handling
// exist here. If you do not wish to have this automatic handling, use COPY.
//
540340
func add(b *Builder, args []string, attributes map[string]bool, flagArgs []string, original string) error {
	if len(args) < 2 {
		return errAtLeastOneArgument("ADD")
	}
	var chown string
	last := len(args) - 1
	dest := makeAbsolute(args[last], b.RunConfig.WorkingDir)
	if len(flagArgs) > 0 {
		for _, arg := range flagArgs {
			switch {
			case strings.HasPrefix(arg, "--chown="):
				chown = strings.TrimPrefix(arg, "--chown=")
			default:
				return fmt.Errorf("ADD only supports the --chown=<uid:gid> flag")
			}
		}
	}
	b.PendingCopies = append(b.PendingCopies, Copy{Src: args[0:last], Dest: dest, Download: true, Chown: chown})
	return nil
}
505307
func (link *LinkState) AddFile(input JITInputType, path string, options ...JITOption) error {
	argcount, args, argvals := link.encodeArguments(options)

	cpath := C.CString(path)
	err := result(C.cuLinkAddFile(
		link.state, C.CUjitInputType(input),
		cpath,
		argcount, args, argvals,
	))
	C.free(unsafe.Pointer(cpath))
	return err
}
820607
func (a Archive) Add(name, path string) error {
	if a.gw.Header.Name != "" {
		return fmt.Errorf("gzip: failed to add %s, only one file can be archived in gz format", name)
	}
	file, err := os.Open(path) // #nosec
	if err != nil {
		return err
	}
	defer file.Close() // nolint: errcheck
	info, err := file.Stat()
	if err != nil {
		return err
	}
	if info.IsDir() {
		return nil
	}
	a.gw.Header.Name = name
	a.gw.Header.ModTime = info.ModTime()
	_, err = io.Copy(a.gw, file)
	return err
}
931358
func (a Archive) Add(name, path string) (err error) {
	file, err := os.Open(path) // #nosec
	if err != nil {
		return
	}
	defer file.Close() // nolint: errcheck
	info, err := file.Stat()
	if err != nil {
		return
	}
	if info.IsDir() {
		return
	}
	header, err := zip.FileInfoHeader(info)
	if err != nil {
		return err
	}
	header.Name = name
	header.Method = zip.Deflate
	w, err := a.z.CreateHeader(header)
	if err != nil {
		return err
	}
	_, err = io.Copy(w, file)
	return err
}
1223179
func Copypath(dst string, src string) error {
	err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}

		if strings.HasPrefix(filepath.Base(path), ".") {
			if info.IsDir() {
				return filepath.SkipDir
			}
			return nil
		}

		if info.IsDir() {
			return nil
		}

		if info.Mode()&os.ModeSymlink != 0 {
			if debugCopypath {
				fmt.Printf("skipping symlink: %v\n", path)
			}
			return nil
		}

		dst := filepath.Join(dst, path[len(src):])
		return Copyfile(dst, path)
	})
	if err != nil {
		// if there was an error during copying, remove the partial copy.
		RemoveAll(dst)
	}
	return err
}
1041662
func (m *Motto) AddPath(paths ...string) {
	m.pathsMu.Lock()
	m.paths = append(m.paths, paths...)
	m.pathsMu.Unlock()
}
284744
func Clone(ctx context.Context, repo, path string) (*Git, error) {
	g := &Git{
		path: filepath.Dir(path),
	}
	if err := g.Cmd(ctx, "Clone", "clone", repo, path); err != nil {
		return nil, err
	}
	g.path = path
	return g, nil
}
64349
func (l *OSFileSystemLoader) AddPath(path string) {
	l.dirs = append(l.dirs, path)
}
15554
func expandPath(p string) string {
	if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") {
		if home := homeDir(); home != "" {
			p = home + p[1:]
		}
	}
	return path.Clean(os.ExpandEnv(p))
}
1333979
func ExpandPath(f string) (string, error) {
	if !path.IsAbs(f) {
		wd, err := os.Getwd()
		if err != nil {
			return "", err
		}
		fname := path.Clean(path.Join(wd, f))
		return fname, nil
	}

	return f, nil
}
1239027
func ExpandPath(p string) string {
	if strings.HasPrefix(p, "~/") {
		p = homedir.HomeDir() + p[1:]
	}

	return p
}
378076
func (goPlatform *Platform) ValidatePath(rawPath string) error {
	path, err := url.Parse(rawPath)
	if err != nil || path == nil {
		return fmt.Errorf("invalid path: %s", err)
	}

	//we have no real good way of checking existence of remote urls except by downloading and testing
	//which we do later anyway. But we *can* - and *should* - test for existence of local paths.
	//Treat empty scheme as a local filesystem path
	if path.Scheme == "" {
		gopath, err := getGopath()
		if err != nil {
			return err
		}
		pathToCheck := filepath.Join(gopath, "src", rawPath)
		exists, err := pathExists(pathToCheck)
		if err != nil {
			return fmt.Errorf("error validating chaincode path: %s", err)
		}
		if !exists {
			return fmt.Errorf("path to chaincode does not exist: %s", pathToCheck)
		}
	}
	return nil
}
361405
func jsonnet_jpath_add(vmRef *C.struct_JsonnetVm, path *C.char) {
	vm := getVM(vmRef)
	vm.importer.JPaths = append(vm.importer.JPaths, C.GoString(path))
}
982147
func (r *Request) Path(path string) *Request {
	r.Use(url.Path(path))
	return r
}
1333624
func (c *Client) Path(path string) *Client {
	c.Use(url.Path(path))
	return c
}
477854
func (t emptyDirTracker) addFile(path string) {
	dir := filepath.Dir(path)
	for dir != "." {
		delete(t, dir)
		dir = filepath.Dir(dir)
	}
}
458808
func (i *LocalInstaller) Path() string {
	if i.Source == "" {
		return ""
	}
	return filepath.Join(i.Home.Rigs(), i.Name)
}