// AddMinikubeDirToAssets adds all the files in the basedir argument to the list
// of files to be copied to the vm.  If vmpath is left blank, the files will be
// transferred to the location according to their relative minikube folder path.
14034
func addMinikubeDirToAssets(basedir, vmpath string, assets *[]CopyableFile) error {
	err := filepath.Walk(basedir, func(hostpath string, info os.FileInfo, err error) error {
		isDir, err := util.IsDirectory(hostpath)
		if err != nil {
			return errors.Wrapf(err, "checking if %s is directory", hostpath)
		}
		if !isDir {
			vmdir := vmpath
			if vmdir == "" {
				rPath, err := filepath.Rel(basedir, hostpath)
				if err != nil {
					return errors.Wrap(err, "generating relative path")
				}
				rPath = filepath.Dir(rPath)
				rPath = filepath.ToSlash(rPath)
				vmdir = path.Join("/", rPath)
			}
			permString := fmt.Sprintf("%o", info.Mode().Perm())
			// The conversion will strip the leading 0 if present, so add it back
			// if we need to.
			if len(permString) == 3 {
				permString = fmt.Sprintf("0%s", permString)
			}

			f, err := NewFileAsset(hostpath, vmdir, filepath.Base(hostpath), permString)
			if err != nil {
				return errors.Wrapf(err, "creating file asset for %s", hostpath)
			}
			*assets = append(*assets, f)
		}

		return nil
	})
	if err != nil {
		return errors.Wrap(err, "walking filepath")
	}
	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))
}
227790
func (c *Container) PutAssetRequest(filename, contentType string, body io.Reader) (response *SkygearResponse, err error) {
	url := c.assetURL(filename)
	req, err := c.createRequest("PUT", url, contentType, body)
	if err != nil {
		return nil, err
	}

	jsonDataFromHTTP, err := getBytesResponse(req)
	if err != nil {
		return nil, err
	}

	var jsonData map[string]interface{}
	err = json.Unmarshal(jsonDataFromHTTP, &jsonData)
	if err != nil {
		return nil, err
	}

	return &SkygearResponse{Payload: jsonData}, nil
}
994720
func findAssets(pkgDir string, exts []string) (assetMap, error) {
	assets := assetMap{}

	err := filepath.Walk(pkgDir, func(path string, info os.FileInfo, err error) error {
		if err != nil || info.IsDir() || !isAssetFile(path, exts) {
			return err
		}
		rel, err := filepath.Rel(pkgDir, path)
		if err != nil {
			return err
		}
		blob, err := ioutil.ReadFile(path)
		if err != nil {
			return err
		}
		assets[filepath.ToSlash(rel)] = asset{
			Path: filepath.ToSlash(rel),
			Body: blob,
		}
		return nil
	})

	if err != nil {
		return nil, err
	}
	return assets, nil
}
808629
func (fs *FSObjects) ListMultipartUploads(ctx context.Context, bucket, object, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result ListMultipartsInfo, e error) {
	if err := checkListMultipartArgs(ctx, bucket, object, keyMarker, uploadIDMarker, delimiter, fs); err != nil {
		return result, toObjectErr(err)
	}

	if _, err := fs.statBucketDir(ctx, bucket); err != nil {
		return result, toObjectErr(err, bucket)
	}

	result.MaxUploads = maxUploads
	result.KeyMarker = keyMarker
	result.Prefix = object
	result.Delimiter = delimiter
	result.NextKeyMarker = object
	result.UploadIDMarker = uploadIDMarker

	uploadIDs, err := readDir(fs.getMultipartSHADir(bucket, object))
	if err != nil {
		if err == errFileNotFound {
			result.IsTruncated = false
			return result, nil
		}
		logger.LogIf(ctx, err)
		return result, toObjectErr(err)
	}

	// S3 spec says uploaIDs should be sorted based on initiated time. ModTime of fs.json
	// is the creation time of the uploadID, hence we will use that.
	var uploads []MultipartInfo
	for _, uploadID := range uploadIDs {
		metaFilePath := pathJoin(fs.getMultipartSHADir(bucket, object), uploadID, fs.metaJSONFile)
		fi, err := fsStatFile(ctx, metaFilePath)
		if err != nil {
			return result, toObjectErr(err, bucket, object)
		}
		uploads = append(uploads, MultipartInfo{
			Object:    object,
			UploadID:  strings.TrimSuffix(uploadID, slashSeparator),
			Initiated: fi.ModTime(),
		})
	}
	sort.Slice(uploads, func(i int, j int) bool {
		return uploads[i].Initiated.Before(uploads[j].Initiated)
	})

	uploadIndex := 0
	if uploadIDMarker != "" {
		for uploadIndex < len(uploads) {
			if uploads[uploadIndex].UploadID != uploadIDMarker {
				uploadIndex++
				continue
			}
			if uploads[uploadIndex].UploadID == uploadIDMarker {
				uploadIndex++
				break
			}
			uploadIndex++
		}
	}
	for uploadIndex < len(uploads) {
		result.Uploads = append(result.Uploads, uploads[uploadIndex])
		result.NextUploadIDMarker = uploads[uploadIndex].UploadID
		uploadIndex++
		if len(result.Uploads) == maxUploads {
			break
		}
	}

	result.IsTruncated = uploadIndex < len(uploads)

	if !result.IsTruncated {
		result.NextKeyMarker = ""
		result.NextUploadIDMarker = ""
	}

	return result, nil
}
779843
func RestoreAssets(dir, name string) error {
	children, err := AssetDir(name)
	// File
	if err != nil {
		return RestoreAsset(dir, name)
	}
	// Dir
	for _, child := range children {
		err = RestoreAssets(dir, filepath.Join(name, child))
		if err != nil {
			return err
		}
	}
	return nil
}
132524
func addFileAttribute(a *dokan.Stat, fa dokan.FileAttribute) {
	// FileAttributeNormal is valid only if no other attribute is set.
	// Thus clear the normal flag (if set) from the attributes and or
	// the new flag.
	a.FileAttributes = (a.FileAttributes &^ dokan.FileAttributeNormal) | fa
}
823955
func (ta *tarAppender) addTarFile(path, name string) error {
	fi, err := os.Lstat(path)
	if err != nil {
		return err
	}

	var link string
	if fi.Mode()&os.ModeSymlink != 0 {
		var err error
		link, err = os.Readlink(path)
		if err != nil {
			return err
		}
	}

	hdr, err := FileInfoHeader(name, fi, link)
	if err != nil {
		return err
	}
	if err := ReadSecurityXattrToTarHeader(path, hdr); err != nil {
		return err
	}

	// if it's not a directory and has more than 1 link,
	// it's hard linked, so set the type flag accordingly
	if !fi.IsDir() && hasHardlinks(fi) {
		inode, err := getInodeFromStat(fi.Sys())
		if err != nil {
			return err
		}
		// a link should have a name that it links too
		// and that linked name should be first in the tar archive
		if oldpath, ok := ta.SeenFiles[inode]; ok {
			hdr.Typeflag = tar.TypeLink
			hdr.Linkname = oldpath
			hdr.Size = 0 // This Must be here for the writer math to add up!
		} else {
			ta.SeenFiles[inode] = name
		}
	}

	//check whether the file is overlayfs whiteout
	//if yes, skip re-mapping container ID mappings.
	isOverlayWhiteout := fi.Mode()&os.ModeCharDevice != 0 && hdr.Devmajor == 0 && hdr.Devminor == 0

	//handle re-mapping container ID mappings back to host ID mappings before
	//writing tar headers/files. We skip whiteout files because they were written
	//by the kernel and already have proper ownership relative to the host
	if !isOverlayWhiteout &&
		!strings.HasPrefix(filepath.Base(hdr.Name), WhiteoutPrefix) &&
		!ta.IDMappings.Empty() {
		fileIDPair, err := getFileUIDGID(fi.Sys())
		if err != nil {
			return err
		}
		hdr.Uid, hdr.Gid, err = ta.IDMappings.ToContainer(fileIDPair)
		if err != nil {
			return err
		}
	}

	// explicitly override with ChownOpts
	if ta.ChownOpts != nil {
		hdr.Uid = ta.ChownOpts.UID
		hdr.Gid = ta.ChownOpts.GID
	}

	if ta.WhiteoutConverter != nil {
		wo, err := ta.WhiteoutConverter.ConvertWrite(hdr, path, fi)
		if err != nil {
			return err
		}

		// If a new whiteout file exists, write original hdr, then
		// replace hdr with wo to be written after. Whiteouts should
		// always be written after the original. Note the original
		// hdr may have been updated to be a whiteout with returning
		// a whiteout header
		if wo != nil {
			if err := ta.TarWriter.WriteHeader(hdr); err != nil {
				return err
			}
			if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 {
				return fmt.Errorf("tar: cannot use whiteout for non-empty file")
			}
			hdr = wo
		}
	}

	if err := ta.TarWriter.WriteHeader(hdr); err != nil {
		return err
	}

	if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 {
		// We use system.OpenSequential to ensure we use sequential file
		// access on Windows to avoid depleting the standby list.
		// On Linux, this equates to a regular os.Open.
		file, err := system.OpenSequential(path)
		if err != nil {
			return err
		}

		ta.Buffer.Reset(ta.TarWriter)
		defer ta.Buffer.Reset(nil)
		_, err = io.Copy(ta.Buffer, file)
		file.Close()
		if err != nil {
			return err
		}
		err = ta.Buffer.Flush()
		if err != nil {
			return err
		}
	}

	return nil
}
442881
func addKnownTypes(scheme *runtime.Scheme) error {
	scheme.AddKnownTypes(GroupVersion,
		&ImagePolicyConfig{},
	)
	return nil
}
540697
func (tz *TzArchive) AddDir(dirPath, absPath string) error {
	dir, err := os.Open(absPath)
	if err != nil {
		return err
	}
	defer dir.Close()

	tz.AddEmptyDir(dirPath)

	fis, err := dir.Readdir(0)
	if err != nil {
		return err
	}
	for _, fi := range fis {
		curPath := strings.Replace(absPath+"/"+fi.Name(), "\\", "/", -1)
		tmpRecPath := strings.Replace(filepath.Join(dirPath, fi.Name()), "\\", "/", -1)
		if fi.IsDir() {
			if err = tz.AddDir(tmpRecPath, curPath); err != nil {
				return err
			}
		} else {
			if err = tz.AddFile(tmpRecPath, curPath); err != nil {
				return err
			}
		}
	}
	return nil
}
247447
func AssetSliceToAssetBase(path []stellar1.Asset) []stellarnet.AssetBase {
	a := make([]stellarnet.AssetBase, len(path))
	for i, p := range path {
		a[i] = p
	}
	return a
}
92351
func AddKubeConfigDirFlag(fs *pflag.FlagSet, kubeConfigDir *string) {
	fs.StringVar(kubeConfigDir, KubeconfigDir, *kubeConfigDir, "The path where to save the kubeconfig file.")
}
384490
func AddImagesCommonConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta2.InitConfiguration, cfgPath *string, featureGatesString *string) {
	options.AddKubernetesVersionFlag(flagSet, &cfg.ClusterConfiguration.KubernetesVersion)
	options.AddFeatureGatesStringFlag(flagSet, featureGatesString)
	options.AddImageMetaFlags(flagSet, &cfg.ImageRepository)
	flagSet.StringVar(cfgPath, "config", *cfgPath, "Path to kubeadm config file.")
}
1085108
func (c *Client) AddSecondaryStorage(p *AddSecondaryStorageParameter) (*ImageStore, error) {
	obj, err := c.Request("addSecondaryStorage", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*ImageStore), err
}
939894
func (c *ApplyClusterCmd) AddFileAssets(assetBuilder *assets.AssetBuilder) error {

	var baseURL string
	var err error
	if components.IsBaseURL(c.Cluster.Spec.KubernetesVersion) {
		baseURL = c.Cluster.Spec.KubernetesVersion
	} else {
		baseURL = "https://storage.googleapis.com/kubernetes-release/release/v" + c.Cluster.Spec.KubernetesVersion
	}

	k8sAssetsNames := []string{
		"/bin/linux/amd64/kubelet",
		"/bin/linux/amd64/kubectl",
	}
	if needsMounterAsset(c.Cluster, c.InstanceGroups) {
		k8sVersion, err := util.ParseKubernetesVersion(c.Cluster.Spec.KubernetesVersion)
		if err != nil {
			return fmt.Errorf("unable to determine kubernetes version from %q", c.Cluster.Spec.KubernetesVersion)
		} else if util.IsKubernetesGTE("1.9", *k8sVersion) {
			// Available directly
			k8sAssetsNames = append(k8sAssetsNames, "/bin/linux/amd64/mounter")
		} else {
			// Only available in the kubernetes-manifests.tar.gz directory
			k8sAssetsNames = append(k8sAssetsNames, "/kubernetes-manifests.tar.gz")
		}
	}

	for _, a := range k8sAssetsNames {
		k, err := url.Parse(baseURL)
		if err != nil {
			return err
		}
		k.Path = path.Join(k.Path, a)

		u, hash, err := assetBuilder.RemapFileAndSHA(k)
		if err != nil {
			return err
		}
		c.Assets = append(c.Assets, BuildMirroredAsset(u, hash))
	}

	if usesCNI(c.Cluster) {
		cniAsset, cniAssetHash, err := findCNIAssets(c.Cluster, assetBuilder)
		if err != nil {
			return err
		}

		c.Assets = append(c.Assets, BuildMirroredAsset(cniAsset, cniAssetHash))
	}

	if c.Cluster.Spec.Networking.LyftVPC != nil {
		var hash *hashing.Hash

		urlString := os.Getenv("LYFT_VPC_DOWNLOAD_URL")
		if urlString == "" {
			urlString = "https://github.com/lyft/cni-ipvlan-vpc-k8s/releases/download/v0.4.2/cni-ipvlan-vpc-k8s-v0.4.2.tar.gz"
			hash, err = hashing.FromString("bfdc65028a3bf8ffe14388fca28ede3600e7e2dee4e781908b6a23f9e79f86ad")
			if err != nil {
				// Should be impossible
				return fmt.Errorf("invalid hard-coded hash for lyft url")
			}
		} else {
			glog.Warningf("Using url from LYFT_VPC_DOWNLOAD_URL env var: %q", urlString)
		}

		u, err := url.Parse(urlString)
		if err != nil {
			return fmt.Errorf("unable to parse lyft-vpc URL %q", urlString)
		}

		c.Assets = append(c.Assets, BuildMirroredAsset(u, hash))
	}

	// TODO figure out if we can only do this for CoreOS only and GCE Container OS
	// TODO It is very difficult to pre-determine what OS an ami is, and if that OS needs socat
	// At this time we just copy the socat and conntrack binaries to all distros.
	// Most distros will have their own socat and conntrack binary.
	// Container operating systems like CoreOS need to have socat and conntrack added to them.
	{
		utilsLocation, hash, err := KopsFileUrl("linux/amd64/utils.tar.gz", assetBuilder)
		if err != nil {
			return err
		}
		c.Assets = append(c.Assets, BuildMirroredAsset(utilsLocation, hash))
	}

	n, hash, err := NodeUpLocation(assetBuilder)
	if err != nil {
		return err
	}
	c.NodeUpSource = n.String()
	c.NodeUpHash = hash.Hex()

	// Explicitly add the protokube image,
	// otherwise when the Target is DryRun this asset is not added
	// Is there a better way to call this?
	_, _, err = ProtokubeImageSource(assetBuilder)
	if err != nil {
		return err
	}

	return nil
}
200010
func substituteAsset(ctx context.Context, asset string, substitutions interface{}) (string, error) {
	return substitute(ctx, string(GetAsset(asset)), substitutions)
}
995735
func (f *Field) AddRemoteAvailableShards(b *roaring.Bitmap) error {
	f.mergeRemoteAvailableShards(b)
	// Save the updated bitmap to the data store.
	return f.saveAvailableShards()
}