// copy all library files to apidocs directory
331026
func copyLibrariesFiles(uses map[string]string, libs map[string]*raml.Library, ramlFile, dir string,
	libRootURLs []string) error {
	baseDir := filepath.Dir(ramlFile)
	// copy library files
	for _, path := range uses {
		if err := copyFile(baseDir, path, dir, libRootURLs); err != nil {
			return err
		}
	}

	// do it recursively
	for _, l := range libs {
		if err := copyLibrariesFiles(l.Uses, l.Libraries, filepath.Join(baseDir, l.Filename),
			filepath.Join(dir, filepath.Dir(l.Filename)), libRootURLs); err != nil {
			return err
		}
	}
	return nil
}
473605
func (c oauthClient) Files() ([]wl.File, error) {
	lists, err := c.Lists()
	if err != nil {
		return nil, err
	}

	listCount := len(lists)
	c.logger.Debug(
		"files",
		map[string]interface{}{"listCount": listCount},
	)

	filesChan := make(chan []wl.File, listCount)
	idErrChan := make(chan idErr, listCount)
	for _, l := range lists {
		go func(list wl.List) {
			c.logger.Debug(
				"files - getting files for list",
				map[string]interface{}{"listID": list.ID},
			)
			files, err := c.FilesForListID(list.ID)
			idErrChan <- idErr{idType: "list", id: list.ID, err: err}
			filesChan <- files
		}(l)
	}

	e := multiIDErr{}
	for i := 0; i < listCount; i++ {
		idErr := <-idErrChan
		if idErr.err != nil {
			c.logger.Debug(
				"files - error received getting files for list",
				map[string]interface{}{"listID": idErr.id, "err": err},
			)
			e.addError(idErr)
		}
	}

	allFiles := []wl.File{}
	for i := 0; i < listCount; i++ {
		files := <-filesChan
		allFiles = append(allFiles, files...)
	}

	if len(e.errors()) > 0 {
		return allFiles, e
	}

	return allFiles, nil
}
385264
func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error {
	query := url.Values{}
	query.Set("path", filepath.ToSlash(dstPath)) // Normalize the paths used in the API.
	// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
	if !options.AllowOverwriteDirWithFile {
		query.Set("noOverwriteDirNonDir", "true")
	}

	if options.CopyUIDGID {
		query.Set("copyUIDGID", "true")
	}

	apiPath := "/containers/" + containerID + "/archive"

	response, err := cli.putRaw(ctx, apiPath, query, content, nil)
	defer ensureReaderClosed(response)
	if err != nil {
		return wrapResponseError(err, response, "container:path", containerID+":"+dstPath)
	}

	// TODO this code converts non-error status-codes (e.g., "204 No Content") into an error; verify if this is the desired behavior
	if response.statusCode != http.StatusOK {
		return fmt.Errorf("unexpected status code from daemon: %d", response.statusCode)
	}

	return nil
}
720141
func NewAPIDocsGen(basePath string, services []*component.Service) *APIDocsGen {
	return &APIDocsGen{
		basePath: basePath,
		services: services,
	}
}
675915
func (apiDef *APIDefinition) FindLibFile(name string) (string, string) {
	// search in it's document
	if filename, ok := apiDef.Uses[name]; ok {
		return "", filename
	}

	// search in included libraries
	for _, lib := range apiDef.Libraries {
		if filename, ok := lib.Uses[name]; ok {
			return filepath.Dir(lib.Filename), filename
		}
	}
	return "", ""
}
72674
func (gr *goResource) generateAPIImplementations(dir string) error {
	// generate the main API impl file, which only contains struct
	mainCtx := map[string]interface{}{
		"PackageName": gr.PackageName,
		"Name":        gr.Name,
		"Endpoint":    gr.Endpoint,
	}

	mainFile := filepath.Join(dir, strings.ToLower(gr.Name)+"_api")
	if err := commons.GenerateFile(mainCtx, "./templates/golang/server_resource_api_main_go.tmpl",
		"server_resource_api_main_go", mainFile+".go", false); err != nil {
		return err
	}

	// generate per methods file
	for _, sm := range gr.Methods {
		ctx := map[string]interface{}{
			"Method":      sm,
			"APIName":     gr.Name,
			"PackageName": gr.PackageName,
		}
		filename := mainFile + "_" + sm.MethodName + ".go"
		if err := commons.GenerateFile(ctx, "./templates/golang/server_resource_api_impl_go.tmpl",
			"server_resource_api_impl_go", filename, false); err != nil {
			return err
		}
	}
	return nil
}
776298
func (_m *ContainerRuntimeExecutor) CopyFile(containerID string, sourcePath string, destPath string) error {
	ret := _m.Called(containerID, sourcePath, destPath)

	var r0 error
	if rf, ok := ret.Get(0).(func(string, string, string) error); ok {
		r0 = rf(containerID, sourcePath, destPath)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
326521
func (d *EphemeralDisk) Copy() *EphemeralDisk {
	ld := new(EphemeralDisk)
	*ld = *d
	return ld
}
69067
func (pb *PackageBuilder) ForceMetadataFiles() ForceMetadataFiles {
	pb.Files["package.xml"] = pb.PackageXml()
	return pb.Files
}
925859
func addlibpath(ctxt *Link, srcref string, objref string, file string, pkg string) {
	for i := range ctxt.Library {
		if file == ctxt.Library[i].File {
			return
		}
	}
	if ctxt.Debugvlog > 1 && ctxt.Bso != nil {
		Bprint(ctxt.Bso, "%5.2f addlibpath: srcref: %s objref: %s file: %s pkg: %s\n", Cputime(), srcref, objref, file, pkg)
	}
	ctxt.Library = append(ctxt.Library, Library{
		Objref: objref,
		Srcref: srcref,
		File:   file,
		Pkg:    pkg,
	})
}
345537
func copyOneToolsPackage(toolsDir, stream string, tools *coretools.Tools, u ToolsUploader) error {
	toolsName := envtools.StorageName(tools.Version, toolsDir)
	logger.Infof("downloading %q %v (%v)", stream, toolsName, tools.URL)
	resp, err := utils.GetValidatingHTTPClient().Get(tools.URL)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	// Verify SHA-256 hash.
	var buf bytes.Buffer
	sha256, size, err := utils.ReadSHA256(io.TeeReader(resp.Body, &buf))
	if err != nil {
		return err
	}
	if tools.SHA256 == "" {
		logger.Errorf("no SHA-256 hash for %v", tools.SHA256) // TODO(dfc) can you spot the bug ?
	} else if sha256 != tools.SHA256 {
		return errors.Errorf("SHA-256 hash mismatch (%v/%v)", sha256, tools.SHA256)
	}
	sizeInKB := (size + 512) / 1024
	logger.Infof("uploading %v (%dkB) to model", toolsName, sizeInKB)
	return u.UploadTools(toolsDir, stream, tools, buf.Bytes())
}
99991
func replaceableFoldersFunc(dataDir string, mongoVersion mongo.Version) (map[string]os.FileMode, error) {
	replaceables := map[string]os.FileMode{}

	// NOTE: never put dataDir in here directly as that will unconditionally
	// remove the database.
	dirs := []string{
		filepath.Join(dataDir, "init"),
		filepath.Join(dataDir, "tools"),
		filepath.Join(dataDir, "agents"),
	}
	if mongoVersion.Major == 2 {
		dirs = append(dirs, filepath.Join(dataDir, "db"))
	}

	for _, replaceable := range dirs {
		dirStat, err := os.Stat(replaceable)
		if os.IsNotExist(err) {
			continue
		}
		if err != nil {
			return map[string]os.FileMode{}, errors.Annotatef(err, "cannot stat %q", replaceable)
		}
		replaceables[replaceable] = dirStat.Mode()
	}
	return replaceables, nil
}
852005
func CopyDir(dst, src string) error {
	err := os.MkdirAll(dst, 0755)
	if err != nil {
		return err
	}

	files, err := ioutil.ReadDir(src)

	for i := 0; i < len(files) && err == nil; i++ {
		file := files[i].Name()
		df := filepath.Join(dst, file)
		sf := filepath.Join(src, file)
		if IsFile(sf) {
			err = Copy(df, sf)
		} else {
			err = CopyDir(df, sf)
		}
	}

	return err
}
81763
func (k *SimpleFS) SimpleFSCopy(ctx context.Context, arg keybase1.SimpleFSCopyArg) 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.doCopy(ctx, arg.OpID, arg.Src, arg.Dest)
		})
}
345467
func (c *Files) Copy(in *CopyInput) (out *CopyOutput, err error) {
	body, err := c.call("/files/copy", in)
	if err != nil {
		return
	}
	defer body.Close()

	err = json.NewDecoder(body).Decode(&out)
	return
}
155541
func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
	query := make(url.Values, 1)
	query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API.

	apiPath := "/containers/" + containerID + "/archive"
	response, err := cli.get(ctx, apiPath, query, nil)
	if err != nil {
		return nil, types.ContainerPathStat{}, wrapResponseError(err, response, "container:path", containerID+":"+srcPath)
	}

	// TODO this code converts non-error status-codes (e.g., "204 No Content") into an error; verify if this is the desired behavior
	if response.statusCode != http.StatusOK {
		return nil, types.ContainerPathStat{}, fmt.Errorf("unexpected status code from daemon: %d", response.statusCode)
	}

	// In order to get the copy behavior right, we need to know information
	// about both the source and the destination. The response headers include
	// stat info about the source that we can use in deciding exactly how to
	// copy it locally. Along with the stat info about the local destination,
	// we have everything we need to handle the multiple possibilities there
	// can be when copying a file/dir from one location to another file/dir.
	stat, err := getContainerPathStatFromHeader(response.header)
	if err != nil {
		return nil, stat, fmt.Errorf("unable to get resource stat from response: %s", err)
	}
	return response.body, stat, err
}
362389
func (ctx *Context) CopyPackage(destPath, srcPath, lookRoot, pkgPath string, ignoreFiles []string, tree bool, h hash.Hash, beforeCopy func(deps []string) error) error {
	if pathos.FileStringEquals(destPath, srcPath) {
		return fmt.Errorf("Attempting to copy package to same location %q.", destPath)
	}
	err := os.MkdirAll(destPath, 0777)
	if err != nil {
		return err
	}

	// Ensure the dest is empty of files.
	destDir, err := os.Open(destPath)
	if err != nil {
		return err
	}
	ignoreTest := false
	for _, ignore := range ctx.ignoreTag {
		if ignore == "test" {
			ignoreTest = true
			break
		}
	}

	fl, err := destDir.Readdir(-1)
	destDir.Close()
	if err != nil {
		return err
	}
	for _, fi := range fl {
		if fi.IsDir() {
			if tree {
				err = errors.Wrap(os.RemoveAll(filepath.Join(destPath, fi.Name())), "remove all existing tree entries")
				if err != nil {
					return err
				}
			}
			continue
		}
		err = errors.Wrap(os.Remove(filepath.Join(destPath, fi.Name())), "remove existing file")
		if err != nil {
			return err
		}
	}

	// Copy files into dest.
	srcDir, err := os.Open(srcPath)
	if err != nil {
		return errors.Wrap(err, "open srcPath directory")
	}

	fl, err = srcDir.Readdir(-1)
	srcDir.Close()
	if err != nil {
		return errors.Wrap(err, "src readdir")
	}
	if h != nil {
		// Write relative path to GOPATH.
		h.Write([]byte(strings.Trim(pkgPath, "/")))
		// Sort file list to present a stable hash.
		sort.Sort(fileInfoSort(fl))
	}
fileLoop:
	for _, fi := range fl {
		name := fi.Name()
		if name[0] == '.' {
			continue
		}
		if fi.IsDir() {
			isTestdata := name == "testdata"
			if !tree && !isTestdata {
				continue
			}
			if name[0] == '_' {
				continue
			}
			if ignoreTest {
				if strings.HasSuffix(name, "_test") || isTestdata {
					continue
				}
			}
			nextDestPath := filepath.Join(destPath, name)
			nextSrcPath := filepath.Join(srcPath, name)
			var nextIgnoreFiles, deps []string
			if !isTestdata && !strings.Contains(pkgPath, "/testdata/") {
				nextIgnoreFiles, deps, err = ctx.getIgnoreFiles(nextSrcPath)
				if err != nil {
					return err
				}
			}
			if beforeCopy != nil {
				err = beforeCopy(deps)
				if err != nil {
					return errors.Wrap(err, "beforeCopy")
				}
			}
			err = ctx.CopyPackage(nextDestPath, nextSrcPath, lookRoot, path.Join(pkgPath, name), nextIgnoreFiles, true, h, beforeCopy)
			if err != nil {
				return errors.Wrapf(err,
					"CopyPackage dest=%q src=%q lookRoot=%q pkgPath=%q ignoreFiles=%q tree=%t has beforeCopy=%t",
					nextDestPath, nextSrcPath, lookRoot, path.Join(pkgPath, name), nextIgnoreFiles, true, beforeCopy != nil,
				)
			}
			continue
		}
		for _, ignore := range ignoreFiles {
			if pathos.FileStringEquals(name, ignore) {
				continue fileLoop
			}
		}
		if h != nil {
			h.Write([]byte(name))
		}
		err = copyFile(
			filepath.Join(destPath, name),
			filepath.Join(srcPath, name),
			h,
		)
		if err != nil {
			return errors.Wrapf(err, "copyFile dest=%q src=%q", filepath.Join(destPath, name), filepath.Join(srcPath, name))
		}
	}

	return errors.Wrapf(licenseCopy(lookRoot, srcPath, filepath.Join(ctx.RootDir, ctx.VendorFolder), pkgPath), "licenseCopy srcPath=%q", srcPath)
}