// findCreatesDirParents finds the tasks which create parent directories for the given task
971402
func findCreatesDirParents(p string, tasks map[string]fi.Task) []fi.Task {
	var deps []fi.Task
	for _, v := range tasks {
		if createsDirectory, ok := v.(CreatesDir); ok {
			dirPath := createsDirectory.Dir()
			if dirPath != "" {
				if !strings.HasSuffix(dirPath, "/") {
					dirPath += "/"
				}

				if p == dirPath {
					continue
				}

				if strings.HasPrefix(p, dirPath) {
					deps = append(deps, v)
				}
			}
		}
	}
	return deps
}
746016
func DirEntryMapToDirEntries(entryMap map[string]DirEntry) DirEntries {
	dirEntries := make(DirEntries, 0, len(entryMap))
	for name, entry := range entryMap {
		dirEntries = append(dirEntries, DirEntryWithName{entry, name})
	}
	return dirEntries
}
811918
func (o *VMPowerOn) GetDependencies(tasks map[string]fi.Task) []fi.Task {
	var deps []fi.Task
	attachISOTask := tasks["AttachISO/"+*o.AttachISO.Name]
	if attachISOTask == nil {
		glog.Fatalf("Unable to find attachISO task %s dependency for VMPowerOn %s", *o.AttachISO.Name, *o.Name)
	}
	deps = append(deps, attachISOTask)
	return deps
}
436527
func FindTaskDependencies(tasks map[string]Task) map[string][]string {
	taskToId := make(map[interface{}]string)
	for k, t := range tasks {
		taskToId[t] = k
	}

	edges := make(map[string][]string)

	for k, t := range tasks {
		task := t.(Task)

		var dependencies []Task
		if hd, ok := task.(HasDependencies); ok {
			dependencies = hd.GetDependencies(tasks)
		} else {
			dependencies = reflectForDependencies(tasks, task)
		}

		var dependencyKeys []string
		for _, dep := range dependencies {
			dependencyKey, found := taskToId[dep]
			if !found {
				glog.Fatalf("dependency not found: %v", dep)
			}
			dependencyKeys = append(dependencyKeys, dependencyKey)
		}

		edges[k] = dependencyKeys
	}

	glog.V(4).Infof("Dependencies:")
	for k, v := range edges {
		glog.V(4).Infof("\t%s:\t%v", k, v)
	}

	return edges
}
829583
func (c *Corpus) GetDirChildren(ctx context.Context, dirRef blob.Ref) (map[blob.Ref]struct{}, error) {
	children, ok := c.dirChildren[dirRef]
	if !ok {
		if _, ok := c.files[dirRef]; !ok {
			return nil, os.ErrNotExist
		}
		return nil, nil
	}
	return children, nil
}
1181931
func (b *Builder) AddDirRecursive(dir string) error {
	// Add the root.
	if _, err := b.importPackage(dir, true); err != nil {
		klog.Warningf("Ignoring directory %v: %v", dir, err)
	}

	// filepath.Walk includes the root dir, but we already did that, so we'll
	// remove that prefix and rebuild a package import path.
	prefix := b.buildPackages[dir].Dir
	fn := func(filePath string, info os.FileInfo, err error) error {
		if info != nil && info.IsDir() {
			rel := filepath.ToSlash(strings.TrimPrefix(filePath, prefix))
			if rel != "" {
				// Make a pkg path.
				pkg := path.Join(string(canonicalizeImportPath(b.buildPackages[dir].ImportPath)), rel)

				// Add it.
				if _, err := b.importPackage(pkg, true); err != nil {
					klog.Warningf("Ignoring child directory %v: %v", pkg, err)
				}
			}
		}
		return nil
	}
	if err := filepath.Walk(b.buildPackages[dir].Dir, fn); err != nil {
		return err
	}
	return nil
}
1261529
func (b *KubeletBuilder) buildManifestDirectory(kubeletConfig *kops.KubeletConfigSpec) (*nodetasks.File, error) {
	directory := &nodetasks.File{
		Path: kubeletConfig.PodManifestPath,
		Type: nodetasks.FileType_Directory,
		Mode: s("0755"),
	}
	return directory, nil
}
410378
func (e *Package) GetDependencies(tasks map[string]fi.Task) []fi.Task {
	var deps []fi.Task

	// UpdatePackages before we install any packages
	for _, v := range tasks {
		if _, ok := v.(*UpdatePackages); ok {
			deps = append(deps, v)
		}
	}

	// If this package is a bare deb, install it after OS managed packages
	if !e.isOSPackage() {
		for _, v := range tasks {
			if vp, ok := v.(*Package); ok {
				if vp.isOSPackage() {
					deps = append(deps, v)
				}
			}
		}
	}

	return deps
}
1243427
func readOrderedDirNames(c *dhCreator, dirname string) ([]string, error) {
	infos, err := c.fs.Readdir(dirname)
	if err != nil {
		return nil, err
	}

	names := []string{}
	dirnames := []string{}
	for _, info := range infos {
		if info.IsDir() {
			dirnames = append(dirnames, info.Name())
			continue
		}
		names = append(names, info.Name())
	}
	sort.Strings(names)
	sort.Strings(dirnames)
	return append(names, dirnames...), nil
}
693037
func (fs *FSObjects) listDirFactory() ListDirFunc {
	// listDir - lists all the entries at a given prefix and given entry in the prefix.
	listDir := func(bucket, prefixDir, prefixEntry string) (entries []string) {
		var err error
		entries, err = readDir(pathJoin(fs.fsPath, bucket, prefixDir))
		if err != nil && err != errFileNotFound {
			logger.LogIf(context.Background(), err)
			return
		}
		sort.Strings(entries)
		return filterMatchingPrefix(entries, prefixEntry)
	}

	// Return list factory instance.
	return listDir
}
1047723
func GetAllSubDirs(rootPath string) ([]string, error) {
	if !IsDir(rootPath) {
		return nil, errors.New("not a directory or does not exist: " + rootPath)
	}
	return statDir(rootPath, "", true, true, false)
}
761910
func DirExists(dir string) bool {
	fi, err := os.Stat(dir)
	return err == nil && fi.IsDir()
}
964826
func (sdw *SplitDiffWorker) findTargets(ctx context.Context) error {
	sdw.SetState(WorkerStateFindTargets)

	// find an appropriate tablet in destination shard
	var err error
	sdw.destinationAlias, err = FindWorkerTablet(
		ctx,
		sdw.wr,
		sdw.cleaner,
		nil, /* tsc */
		sdw.cell,
		sdw.keyspace,
		sdw.shard,
		1, /* minHealthyTablets */
		sdw.destinationTabletType,
	)
	if err != nil {
		return vterrors.Wrapf(err, "FindWorkerTablet() failed for %v/%v/%v", sdw.cell, sdw.keyspace, sdw.shard)
	}

	// find an appropriate tablet in the source shard
	// During an horizontal shard split, multiple workers will race to get
	// a RDONLY tablet in the source shard. When this happen, concurrent calls
	// to FindWorkerTablet could attempt to set to DRAIN state the same tablet. Only
	// one of these calls to FindWorkerTablet will succeed and the rest will fail.
	// The following, makes sures we keep trying to find a worker tablet when this error occur.
	shortCtx, cancel := context.WithTimeout(ctx, *remoteActionsTimeout)
	for {
		select {
		case <-shortCtx.Done():
			return vterrors.Errorf(vtrpc.Code_ABORTED, "could not find healthy table for %v/%v%v: after: %v, aborting", sdw.cell, sdw.keyspace, sdw.sourceShard.Shard, *remoteActionsTimeout)
		default:
			sdw.sourceAlias, err = FindWorkerTablet(ctx, sdw.wr, sdw.cleaner, nil /* tsc */, sdw.cell, sdw.keyspace, sdw.sourceShard.Shard, sdw.minHealthyRdonlyTablets, topodatapb.TabletType_RDONLY)
			if err != nil {
				sdw.wr.Logger().Infof("FindWorkerTablet() failed for %v/%v/%v: %v retrying...", sdw.cell, sdw.keyspace, sdw.sourceShard.Shard, err)
				continue
			}
			cancel()
			return nil
		}
	}
}
1201484
func (dd *DirData) GetDirtyChildPtrs(
	ctx context.Context, dirtyBcache IsDirtyProvider) (
	ptrs map[BlockPointer]bool, err error) {
	topBlock, err := dd.GetTopBlock(ctx, BlockRead)
	if err != nil {
		return nil, err
	}

	if !topBlock.IsIndirect() {
		return nil, nil
	}

	ptrs = make(map[BlockPointer]bool)

	// Gather all the paths to all dirty leaf blocks first.
	off := topBlock.FirstOffset()
	for off != nil {
		_, parentBlocks, block, nextBlockOff, _, err :=
			dd.tree.getNextDirtyBlockAtOffset(
				ctx, topBlock, off, BlockWrite, dirtyBcache)
		if err != nil {
			return nil, err
		}

		if block == nil {
			// No more dirty blocks.
			break
		}
		off = nextBlockOff // Will be `nil` if there are no more blocks.

		for _, pb := range parentBlocks {
			ptrs[pb.childBlockPtr()] = true
		}
	}
	return ptrs, nil
}
127597
func (c *adminClient) Directories(dirs []string) AdminClient {
	c.dirs = dirs
	return c
}
1091393
func (kz *Kazoo) mkdirRecursive(node string) (err error) {
	parent := path.Dir(node)
	if parent != "/" {
		if err = kz.mkdirRecursive(parent); err != nil {
			return
		}
	}

	exists, _, err := kz.conn.Exists(node)
	if err != nil {
		return
	}

	if !exists {
		_, err = kz.conn.Create(node, nil, 0, zk.WorldACL(zk.PermAll))
		return
	}

	return
}
120509
func taskDiffs(old, new []*Task, contextual bool) ([]*TaskDiff, error) {
	oldMap := make(map[string]*Task, len(old))
	newMap := make(map[string]*Task, len(new))
	for _, o := range old {
		oldMap[o.Name] = o
	}
	for _, n := range new {
		newMap[n.Name] = n
	}

	var diffs []*TaskDiff
	for name, oldGroup := range oldMap {
		// Diff the same, deleted and edited
		diff, err := oldGroup.Diff(newMap[name], contextual)
		if err != nil {
			return nil, err
		}
		diffs = append(diffs, diff)
	}

	for name, newGroup := range newMap {
		// Diff the added
		if old, ok := oldMap[name]; !ok {
			diff, err := old.Diff(newGroup, contextual)
			if err != nil {
				return nil, err
			}
			diffs = append(diffs, diff)
		}
	}

	sort.Sort(TaskDiffs(diffs))
	return diffs, nil
}